﻿using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics.PackedVector;
using Terraria.Audio;
using Terraria.DataStructures;
using Terraria.GameContent;
using Terraria.GameContent.Achievements;
using Terraria.GameContent.Events;
using Terraria.GameContent.Tile_Entities;
using Terraria.GameContent.UI;
using Terraria.ID;
using Terraria.Localization;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using Terraria.Net;
using Terraria.UI;

namespace Terraria
{
	// Token: 0x0200002B RID: 43
	public class MessageBuffer
	{
		// Token: 0x14000009 RID: 9
		// (add) Token: 0x06000393 RID: 915 RVA: 0x00145C2C File Offset: 0x00143E2C
		// (remove) Token: 0x06000394 RID: 916 RVA: 0x00145C60 File Offset: 0x00143E60
		public static event TileChangeReceivedEvent OnTileChangeReceived;

		// Token: 0x06000395 RID: 917 RVA: 0x00145C94 File Offset: 0x00143E94
		public void Reset()
		{
			Array.Clear(this.readBuffer, 0, this.readBuffer.Length);
			Array.Clear(this.writeBuffer, 0, this.writeBuffer.Length);
			this.writeLocked = false;
			this.messageLength = 0;
			this.totalData = 0;
			this.spamCount = 0;
			this.broadcast = false;
			this.checkBytes = false;
			this.ResetReader();
			this.ResetWriter();
		}

		// Token: 0x06000396 RID: 918 RVA: 0x00007E47 File Offset: 0x00006047
		public void ResetReader()
		{
			if (this.readerStream != null)
			{
				this.readerStream.Close();
			}
			this.readerStream = new MemoryStream(this.readBuffer);
			this.reader = new BinaryReader(this.readerStream);
		}

		// Token: 0x06000397 RID: 919 RVA: 0x00007E7E File Offset: 0x0000607E
		public void ResetWriter()
		{
			if (this.writerStream != null)
			{
				this.writerStream.Close();
			}
			this.writerStream = new MemoryStream(this.writeBuffer);
			this.writer = new BinaryWriter(this.writerStream);
		}

		// Token: 0x06000398 RID: 920 RVA: 0x00145D00 File Offset: 0x00143F00
		public void GetData(int start, int length, out int messageType)
		{
			if (this.whoAmI < 256)
			{
				Netplay.Clients[this.whoAmI].TimeOutTimer = 0;
			}
			else
			{
				Netplay.Connection.TimeOutTimer = 0;
			}
			int num = start + 1;
			byte b = this.readBuffer[start];
			messageType = (int)b;
			int num2 = Main.rxMsg;
			Main.rxMsg = num2 + 1;
			Main.rxData += length;
			if ((int)b < Main.maxMsg)
			{
				int[] rxMsgType = Main.rxMsgType;
				byte b2 = b;
				num2 = rxMsgType[(int)b2];
				rxMsgType[(int)b2] = num2 + 1;
				Main.rxDataType[(int)b] += length;
			}
			if (Main.netMode == 1 && Netplay.Connection.StatusMax > 0)
			{
				RemoteServer connection = Netplay.Connection;
				RemoteServer remoteServer = connection;
				num2 = connection.StatusCount;
				remoteServer.StatusCount = num2 + 1;
			}
			if (Main.verboseNetplay)
			{
				for (int i = start; i < start + length; i = num2 + 1)
				{
					num2 = i;
				}
				for (int j = start; j < start + length; j = num2 + 1)
				{
					byte b3 = this.readBuffer[j];
					num2 = j;
				}
			}
			if (Main.netMode == 2 && b != 38 && Netplay.Clients[this.whoAmI].State == -1)
			{
				NetMessage.SendData(2, this.whoAmI, -1, Lang.mp[1].ToNetworkText(), 0, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			if (Main.netMode == 2 && Netplay.Clients[this.whoAmI].State < 10 && b > 12 && b != 93 && b != 16 && b != 42 && b != 50 && b != 38 && b != 68 && b < 250)
			{
				NetMessage.BootPlayer(this.whoAmI, Lang.mp[2].ToNetworkText());
			}
			if (this.reader == null)
			{
				this.ResetReader();
			}
			this.reader.BaseStream.Position = (long)num;
			if (ModNet.HijackGetData(ref b, ref this.reader, this.whoAmI))
			{
				return;
			}
			switch (b)
			{
			case 1:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				if (Main.dedServ && Netplay.IsBanned(Netplay.Clients[this.whoAmI].Socket.GetRemoteAddress()))
				{
					NetMessage.SendData(2, this.whoAmI, -1, Lang.mp[3].ToNetworkText(), 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				if (Netplay.Clients[this.whoAmI].State != 0)
				{
					return;
				}
				string text = this.reader.ReadString();
				ModNet.isModdedClient[this.whoAmI] = (text == ModLoader.versionedName);
				if (!ModNet.isModdedClient[this.whoAmI] && (!(text == "Terraria" + 194) || !ModNet.AllowVanillaClients))
				{
					if (text.StartsWith("tModLoader"))
					{
						NetMessage.SendData(2, this.whoAmI, -1, NetworkText.FromLiteral(Lang.mp[4].Value + string.Format("\n(You are on {0}, server is on {1})", text, ModLoader.versionedName)), 0, 0f, 0f, 0f, 0, 0, 0);
						return;
					}
					NetMessage.SendData(2, this.whoAmI, -1, NetworkText.FromLiteral(Lang.mp[4].Value + "\n(You cannot connect to a tModLoader Server with an unmodded client.)"), 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				else
				{
					if (!string.IsNullOrEmpty(Netplay.ServerPassword))
					{
						Netplay.Clients[this.whoAmI].State = -1;
						NetMessage.SendData(37, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
						return;
					}
					Netplay.Clients[this.whoAmI].State = 1;
					if (ModNet.isModdedClient[this.whoAmI])
					{
						ModNet.SyncMods(this.whoAmI);
						return;
					}
					NetMessage.SendData(3, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				break;
			}
			case 2:
				if (Main.netMode != 1)
				{
					return;
				}
				Netplay.disconnect = true;
				Main.statusText = NetworkText.Deserialize(this.reader).ToString();
				return;
			case 3:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				if (Netplay.Connection.State == 1)
				{
					Netplay.Connection.State = 2;
				}
				int num3 = (int)this.reader.ReadByte();
				if (num3 != Main.myPlayer)
				{
					Main.player[num3] = Main.ActivePlayerFileData.Player;
					Main.player[Main.myPlayer] = new Player(true);
				}
				Main.player[num3].whoAmI = num3;
				Main.myPlayer = num3;
				Player player = Main.player[num3];
				NetMessage.SendData(4, -1, -1, null, num3, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(68, -1, -1, null, num3, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(16, -1, -1, null, num3, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(42, -1, -1, null, num3, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(50, -1, -1, null, num3, 0f, 0f, 0f, 0, 0, 0);
				for (int k = 0; k < 59; k = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)k, (float)player.inventory[k].prefix, 0f, 0, 0, 0);
					num2 = k;
				}
				for (int l = 0; l < player.armor.Length; l = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)(59 + l), (float)player.armor[l].prefix, 0f, 0, 0, 0);
					num2 = l;
				}
				for (int m = 0; m < player.dye.Length; m = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)(58 + player.armor.Length + 1 + m), (float)player.dye[m].prefix, 0f, 0, 0, 0);
					num2 = m;
				}
				for (int n = 0; n < player.miscEquips.Length; n = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)(58 + player.armor.Length + player.dye.Length + 1 + n), (float)player.miscEquips[n].prefix, 0f, 0, 0, 0);
					num2 = n;
				}
				for (int num4 = 0; num4 < player.miscDyes.Length; num4 = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)(58 + player.armor.Length + player.dye.Length + player.miscEquips.Length + 1 + num4), (float)player.miscDyes[num4].prefix, 0f, 0, 0, 0);
					num2 = num4;
				}
				for (int num5 = 0; num5 < player.bank.item.Length; num5 = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)(58 + player.armor.Length + player.dye.Length + player.miscEquips.Length + player.miscDyes.Length + 1 + num5), (float)player.bank.item[num5].prefix, 0f, 0, 0, 0);
					num2 = num5;
				}
				for (int num6 = 0; num6 < player.bank2.item.Length; num6 = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)(58 + player.armor.Length + player.dye.Length + player.miscEquips.Length + player.miscDyes.Length + player.bank.item.Length + 1 + num6), (float)player.bank2.item[num6].prefix, 0f, 0, 0, 0);
					num2 = num6;
				}
				NetMessage.SendData(5, -1, -1, null, num3, (float)(58 + player.armor.Length + player.dye.Length + player.miscEquips.Length + player.miscDyes.Length + player.bank.item.Length + player.bank2.item.Length + 1), (float)player.trashItem.prefix, 0f, 0, 0, 0);
				for (int num7 = 0; num7 < player.bank3.item.Length; num7 = num2 + 1)
				{
					NetMessage.SendData(5, -1, -1, null, num3, (float)(58 + player.armor.Length + player.dye.Length + player.miscEquips.Length + player.miscDyes.Length + player.bank.item.Length + player.bank2.item.Length + 2 + num7), (float)player.bank3.item[num7].prefix, 0f, 0, 0, 0);
					num2 = num7;
				}
				PlayerHooks.SyncPlayer(player, -1, -1, true);
				NetMessage.SendData(6, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				if (Netplay.Connection.State == 2)
				{
					Netplay.Connection.State = 3;
					return;
				}
				return;
			}
			case 4:
			{
				int num8 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num8 = this.whoAmI;
				}
				if (num8 == Main.myPlayer && !Main.ServerSideCharacter)
				{
					return;
				}
				Player player2 = Main.player[num8];
				player2.whoAmI = num8;
				player2.skinVariant = (int)this.reader.ReadByte();
				player2.skinVariant = (int)MathHelper.Clamp((float)player2.skinVariant, 0f, 9f);
				player2.hair = (int)this.reader.ReadByte();
				if (player2.hair >= 134)
				{
					player2.hair = 0;
				}
				player2.name = this.reader.ReadString().Trim().Trim();
				player2.hairDye = this.reader.ReadByte();
				BitsByte bitsByte = this.reader.ReadByte();
				for (int num9 = 0; num9 < 8; num9 = num2 + 1)
				{
					player2.hideVisual[num9] = bitsByte[num9];
					num2 = num9;
				}
				bitsByte = this.reader.ReadByte();
				for (int num10 = 0; num10 < 2; num10 = num2 + 1)
				{
					player2.hideVisual[num10 + 8] = bitsByte[num10];
					num2 = num10;
				}
				player2.hideMisc = this.reader.ReadByte();
				player2.hairColor = this.reader.ReadRGB();
				player2.skinColor = this.reader.ReadRGB();
				player2.eyeColor = this.reader.ReadRGB();
				player2.shirtColor = this.reader.ReadRGB();
				player2.underShirtColor = this.reader.ReadRGB();
				player2.pantsColor = this.reader.ReadRGB();
				player2.shoeColor = this.reader.ReadRGB();
				BitsByte bitsByte2 = this.reader.ReadByte();
				player2.difficulty = 0;
				if (bitsByte2[0])
				{
					Player player3 = player2;
					Player player4 = player3;
					player4.difficulty += 1;
				}
				if (bitsByte2[1])
				{
					Player player5 = player2;
					Player player4 = player5;
					player4.difficulty += 2;
				}
				if (player2.difficulty > 2)
				{
					player2.difficulty = 2;
				}
				player2.extraAccessory = bitsByte2[2];
				if (Main.netMode != 2)
				{
					return;
				}
				bool flag = false;
				if (Netplay.Clients[this.whoAmI].State < 10)
				{
					for (int num11 = 0; num11 < 255; num11 = num2 + 1)
					{
						if (num11 != num8 && player2.name == Main.player[num11].name && Netplay.Clients[num11].IsActive)
						{
							flag = true;
						}
						num2 = num11;
					}
				}
				if (flag)
				{
					NetMessage.SendData(2, this.whoAmI, -1, NetworkText.FromFormattable("{0} {1}", new object[]
					{
						player2.name,
						Lang.mp[5].ToNetworkText()
					}), 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				if (player2.name.Length > Player.nameLen)
				{
					NetMessage.SendData(2, this.whoAmI, -1, NetworkText.FromKey("Net.NameTooLong", new object[0]), 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				if (player2.name == "")
				{
					NetMessage.SendData(2, this.whoAmI, -1, NetworkText.FromKey("Net.EmptyName", new object[0]), 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				Netplay.Clients[this.whoAmI].Name = player2.name;
				Netplay.Clients[this.whoAmI].Name = player2.name;
				NetMessage.SendData(4, -1, this.whoAmI, null, num8, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			case 5:
			{
				int num12 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num12 = this.whoAmI;
				}
				if (num12 == Main.myPlayer && !Main.ServerSideCharacter && !Main.player[num12].IsStackingItems())
				{
					return;
				}
				Player player6 = Main.player[num12];
				Player obj = player6;
				lock (obj)
				{
					int num13 = (int)this.reader.ReadByte();
					int stack = (int)this.reader.ReadInt16();
					int num14 = (int)this.reader.ReadByte();
					int type = (int)this.reader.ReadInt16();
					Item[] array = null;
					int num15 = 0;
					bool flag3 = false;
					if (num13 > 58 + player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length + player6.bank.item.Length + player6.bank2.item.Length + 1)
					{
						num15 = num13 - 58 - (player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length + player6.bank.item.Length + player6.bank2.item.Length + 1) - 1;
						array = player6.bank3.item;
					}
					else if (num13 > 58 + player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length + player6.bank.item.Length + player6.bank2.item.Length)
					{
						flag3 = true;
					}
					else if (num13 > 58 + player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length + player6.bank.item.Length)
					{
						num15 = num13 - 58 - (player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length + player6.bank.item.Length) - 1;
						array = player6.bank2.item;
					}
					else if (num13 > 58 + player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length)
					{
						num15 = num13 - 58 - (player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length) - 1;
						array = player6.bank.item;
					}
					else if (num13 > 58 + player6.armor.Length + player6.dye.Length + player6.miscEquips.Length)
					{
						num15 = num13 - 58 - (player6.armor.Length + player6.dye.Length + player6.miscEquips.Length) - 1;
						array = player6.miscDyes;
					}
					else if (num13 > 58 + player6.armor.Length + player6.dye.Length)
					{
						num15 = num13 - 58 - (player6.armor.Length + player6.dye.Length) - 1;
						array = player6.miscEquips;
					}
					else if (num13 > 58 + player6.armor.Length)
					{
						num15 = num13 - 58 - player6.armor.Length - 1;
						array = player6.dye;
					}
					else if (num13 > 58)
					{
						num15 = num13 - 58 - 1;
						array = player6.armor;
					}
					else
					{
						num15 = num13;
						array = player6.inventory;
					}
					if (flag3)
					{
						player6.trashItem = new Item();
						player6.trashItem.netDefaults(type);
						player6.trashItem.stack = stack;
						player6.trashItem.Prefix(num14);
						ItemIO.ReceiveModData(player6.trashItem, this.reader);
					}
					else if (num13 <= 58)
					{
						int type2 = array[num15].type;
						int stack2 = array[num15].stack;
						array[num15] = new Item();
						array[num15].netDefaults(type);
						array[num15].stack = stack;
						array[num15].Prefix(num14);
						ItemIO.ReceiveModData(array[num15], this.reader);
						if (num12 == Main.myPlayer && num15 == 58)
						{
							Main.mouseItem = array[num15].Clone();
						}
						if (num12 == Main.myPlayer && Main.netMode == 1)
						{
							Main.player[num12].inventoryChestStack[num13] = false;
							if (array[num15].stack != stack2 || array[num15].type != type2)
							{
								Recipe.FindRecipes();
								Main.PlaySound(7, -1, -1, 1, 1f, 0f);
							}
						}
					}
					else
					{
						array[num15] = new Item();
						array[num15].netDefaults(type);
						array[num15].stack = stack;
						array[num15].Prefix(num14);
						ItemIO.ReceiveModData(array[num15], this.reader);
					}
					if (Main.netMode == 2 && num12 == this.whoAmI && num13 <= 58 + player6.armor.Length + player6.dye.Length + player6.miscEquips.Length + player6.miscDyes.Length)
					{
						NetMessage.SendData(5, -1, this.whoAmI, null, num12, (float)num13, (float)num14, 0f, 0, 0, 0);
					}
					return;
				}
				break;
			}
			case 6:
				if (Main.netMode != 2)
				{
					return;
				}
				if (Netplay.Clients[this.whoAmI].State == 1)
				{
					Netplay.Clients[this.whoAmI].State = 2;
				}
				NetMessage.SendData(7, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				Main.SyncAnInvasion(this.whoAmI);
				return;
			case 7:
				break;
			case 8:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int num16 = this.reader.ReadInt32();
				int num17 = this.reader.ReadInt32();
				bool flag4 = true;
				if (num16 == -1 || num17 == -1)
				{
					flag4 = false;
				}
				else if (num16 < 10 || num16 > Main.maxTilesX - 10)
				{
					flag4 = false;
				}
				else if (num17 < 10 || num17 > Main.maxTilesY - 10)
				{
					flag4 = false;
				}
				int num18 = Netplay.GetSectionX(Main.spawnTileX) - 2;
				int num19 = Netplay.GetSectionY(Main.spawnTileY) - 1;
				int num20 = num18 + 5;
				int num21 = num19 + 3;
				if (num18 < 0)
				{
					num18 = 0;
				}
				if (num20 >= Main.maxSectionsX)
				{
					num20 = Main.maxSectionsX - 1;
				}
				if (num19 < 0)
				{
					num19 = 0;
				}
				if (num21 >= Main.maxSectionsY)
				{
					num21 = Main.maxSectionsY - 1;
				}
				int num22 = (num20 - num18) * (num21 - num19);
				List<Point> list = new List<Point>();
				for (int num23 = num18; num23 < num20; num23 = num2 + 1)
				{
					for (int num24 = num19; num24 < num21; num24 = num2 + 1)
					{
						list.Add(new Point(num23, num24));
						num2 = num24;
					}
					num2 = num23;
				}
				int num25 = -1;
				int num26 = -1;
				if (flag4)
				{
					num16 = Netplay.GetSectionX(num16) - 2;
					num17 = Netplay.GetSectionY(num17) - 1;
					num25 = num16 + 5;
					num26 = num17 + 3;
					if (num16 < 0)
					{
						num16 = 0;
					}
					if (num25 >= Main.maxSectionsX)
					{
						num25 = Main.maxSectionsX - 1;
					}
					if (num17 < 0)
					{
						num17 = 0;
					}
					if (num26 >= Main.maxSectionsY)
					{
						num26 = Main.maxSectionsY - 1;
					}
					for (int num27 = num16; num27 < num25; num27 = num2 + 1)
					{
						for (int num28 = num17; num28 < num26; num28 = num2 + 1)
						{
							if (num27 < num18 || num27 >= num20 || num28 < num19 || num28 >= num21)
							{
								list.Add(new Point(num27, num28));
								num2 = num22;
								num22 = num2 + 1;
							}
							num2 = num28;
						}
						num2 = num27;
					}
				}
				int num29 = 1;
				List<Point> list2;
				List<Point> list3;
				PortalHelper.SyncPortalsOnPlayerJoin(this.whoAmI, 1, list, out list2, out list3);
				num22 += list2.Count;
				if (Netplay.Clients[this.whoAmI].State == 2)
				{
					Netplay.Clients[this.whoAmI].State = 3;
				}
				NetMessage.SendData(9, this.whoAmI, -1, Lang.inter[44].ToNetworkText(), num22, 0f, 0f, 0f, 0, 0, 0);
				Netplay.Clients[this.whoAmI].StatusText2 = Language.GetTextValue("Net.IsReceivingTileData");
				RemoteClient remoteClient = Netplay.Clients[this.whoAmI];
				remoteClient.StatusMax += num22;
				for (int num30 = num18; num30 < num20; num30 = num2 + 1)
				{
					for (int num31 = num19; num31 < num21; num31 = num2 + 1)
					{
						NetMessage.SendSection(this.whoAmI, num30, num31, false);
						num2 = num31;
					}
					num2 = num30;
				}
				NetMessage.SendData(11, this.whoAmI, -1, null, num18, (float)num19, (float)(num20 - 1), (float)(num21 - 1), 0, 0, 0);
				if (flag4)
				{
					for (int num32 = num16; num32 < num25; num32 = num2 + 1)
					{
						for (int num33 = num17; num33 < num26; num33 = num2 + 1)
						{
							NetMessage.SendSection(this.whoAmI, num32, num33, true);
							num2 = num33;
						}
						num2 = num32;
					}
					NetMessage.SendData(11, this.whoAmI, -1, null, num16, (float)num17, (float)(num25 - 1), (float)(num26 - 1), 0, 0, 0);
				}
				for (int num34 = 0; num34 < list2.Count; num34 = num2 + 1)
				{
					NetMessage.SendSection(this.whoAmI, list2[num34].X, list2[num34].Y, true);
					num2 = num34;
				}
				for (int num35 = 0; num35 < list3.Count; num35 = num2 + 1)
				{
					NetMessage.SendData(11, this.whoAmI, -1, null, list3[num35].X - num29, (float)(list3[num35].Y - num29), (float)(list3[num35].X + num29 + 1), (float)(list3[num35].Y + num29 + 1), 0, 0, 0);
					num2 = num35;
				}
				for (int num36 = 0; num36 < 400; num36 = num2 + 1)
				{
					if (Main.item[num36].active)
					{
						NetMessage.SendData(21, this.whoAmI, -1, null, num36, 0f, 0f, 0f, 0, 0, 0);
						NetMessage.SendData(22, this.whoAmI, -1, null, num36, 0f, 0f, 0f, 0, 0, 0);
					}
					num2 = num36;
				}
				for (int num37 = 0; num37 < 200; num37 = num2 + 1)
				{
					if (Main.npc[num37].active)
					{
						NetMessage.SendData(23, this.whoAmI, -1, null, num37, 0f, 0f, 0f, 0, 0, 0);
					}
					num2 = num37;
				}
				for (int num38 = 0; num38 < 1000; num38 = num2 + 1)
				{
					if (Main.projectile[num38].active && (Main.projPet[Main.projectile[num38].type] || Main.projectile[num38].netImportant))
					{
						NetMessage.SendData(27, this.whoAmI, -1, null, num38, 0f, 0f, 0f, 0, 0, 0);
					}
					num2 = num38;
				}
				for (int num39 = 0; num39 < 267; num39 = num2 + 1)
				{
					NetMessage.SendData(83, this.whoAmI, -1, null, num39, 0f, 0f, 0f, 0, 0, 0);
					num2 = num39;
				}
				for (int num40 = 580; num40 < NPCLoader.NPCCount; num40 = num2 + 1)
				{
					NetMessage.SendData(83, this.whoAmI, -1, null, num40, 0f, 0f, 0f, 0, 0, 0);
					num2 = num40;
				}
				NetMessage.SendData(49, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(57, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(7, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(103, -1, -1, null, NPC.MoonLordCountdown, 0f, 0f, 0f, 0, 0, 0);
				NetMessage.SendData(101, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			case 9:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				RemoteServer connection = Netplay.Connection;
				connection.StatusMax += this.reader.ReadInt32();
				Netplay.Connection.StatusText = NetworkText.Deserialize(this.reader).ToString();
				return;
			}
			case 10:
				if (Main.netMode != 1)
				{
					return;
				}
				NetMessage.DecompressTileBlock(this.readBuffer, num, length);
				return;
			case 11:
				if (Main.netMode != 1)
				{
					return;
				}
				WorldGen.SectionTileFrame((int)this.reader.ReadInt16(), (int)this.reader.ReadInt16(), (int)this.reader.ReadInt16(), (int)this.reader.ReadInt16());
				return;
			case 12:
			{
				int num41 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num41 = this.whoAmI;
				}
				Player player7 = Main.player[num41];
				player7.SpawnX = (int)this.reader.ReadInt16();
				player7.SpawnY = (int)this.reader.ReadInt16();
				player7.Spawn();
				if (num41 == Main.myPlayer && Main.netMode != 2)
				{
					Main.ActivePlayerFileData.StartPlayTimer();
					Player.Hooks.EnterWorld(Main.myPlayer);
				}
				if (Main.netMode != 2 || Netplay.Clients[this.whoAmI].State < 3)
				{
					return;
				}
				if (Netplay.Clients[this.whoAmI].State == 3)
				{
					Netplay.Clients[this.whoAmI].State = 10;
					NetMessage.greetPlayer(this.whoAmI);
					NetMessage.buffer[this.whoAmI].broadcast = true;
					NetMessage.SyncConnectedPlayer(this.whoAmI);
					NetMessage.SendData(12, -1, this.whoAmI, null, this.whoAmI, 0f, 0f, 0f, 0, 0, 0);
					NetMessage.SendData(74, this.whoAmI, -1, NetworkText.FromLiteral(Main.player[this.whoAmI].name), Main.anglerQuest, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				NetMessage.SendData(12, -1, this.whoAmI, null, this.whoAmI, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			case 13:
			{
				int num42 = (int)this.reader.ReadByte();
				if (num42 == Main.myPlayer && !Main.ServerSideCharacter)
				{
					return;
				}
				if (Main.netMode == 2)
				{
					num42 = this.whoAmI;
				}
				Player player8 = Main.player[num42];
				BitsByte bitsByte3 = this.reader.ReadByte();
				player8.controlUp = bitsByte3[0];
				player8.controlDown = bitsByte3[1];
				player8.controlLeft = bitsByte3[2];
				player8.controlRight = bitsByte3[3];
				player8.controlJump = bitsByte3[4];
				player8.controlUseItem = bitsByte3[5];
				player8.direction = (bitsByte3[6] ? 1 : -1);
				BitsByte bitsByte4 = this.reader.ReadByte();
				if (bitsByte4[0])
				{
					player8.pulley = true;
					player8.pulleyDir = (bitsByte4[1] ? 2 : 1);
				}
				else
				{
					player8.pulley = false;
				}
				player8.selectedItem = (int)this.reader.ReadByte();
				player8.position = this.reader.ReadVector2();
				if (bitsByte4[2])
				{
					player8.velocity = this.reader.ReadVector2();
				}
				else
				{
					player8.velocity = Vector2.Zero;
				}
				player8.vortexStealthActive = bitsByte4[3];
				player8.gravDir = (float)(bitsByte4[4] ? 1 : -1);
				if (Main.netMode == 2 && Netplay.Clients[this.whoAmI].State == 10)
				{
					NetMessage.SendData(13, -1, this.whoAmI, null, num42, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 14:
			{
				int num43 = (int)this.reader.ReadByte();
				int num44 = (int)this.reader.ReadByte();
				if (Main.netMode != 1)
				{
					return;
				}
				bool active = Main.player[num43].active;
				if (num44 == 1)
				{
					if (!Main.player[num43].active)
					{
						Main.player[num43] = new Player(true);
					}
					Main.player[num43].active = true;
				}
				else
				{
					Main.player[num43].active = false;
				}
				if (active == Main.player[num43].active)
				{
					return;
				}
				if (Main.player[num43].active)
				{
					Player.Hooks.PlayerConnect(num43);
					return;
				}
				Player.Hooks.PlayerDisconnect(num43);
				return;
			}
			case 15:
			case 25:
			case 26:
			case 44:
			case 67:
			case 93:
			case 94:
				return;
			case 16:
			{
				int num45 = (int)this.reader.ReadByte();
				if (num45 == Main.myPlayer && !Main.ServerSideCharacter)
				{
					return;
				}
				if (Main.netMode == 2)
				{
					num45 = this.whoAmI;
				}
				Player player9 = Main.player[num45];
				player9.statLife = (int)this.reader.ReadInt16();
				player9.statLifeMax = (int)this.reader.ReadInt16();
				if (player9.statLifeMax < 100)
				{
					player9.statLifeMax = 100;
				}
				player9.dead = (player9.statLife <= 0);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(16, -1, this.whoAmI, null, num45, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 17:
			{
				byte b4 = this.reader.ReadByte();
				int num46 = (int)this.reader.ReadInt16();
				int num47 = (int)this.reader.ReadInt16();
				short num48 = this.reader.ReadInt16();
				int num49 = (int)this.reader.ReadByte();
				bool flag5 = num48 == 1;
				if (!WorldGen.InWorld(num46, num47, 3))
				{
					return;
				}
				if (Main.tile[num46, num47] == null)
				{
					Main.tile[num46, num47] = new Tile();
				}
				if (Main.netMode == 2)
				{
					if (!flag5)
					{
						if (b4 == 0 || b4 == 2 || b4 == 4)
						{
							RemoteClient remoteClient = Netplay.Clients[this.whoAmI];
							remoteClient.SpamDeleteBlock += 1f;
						}
						if (b4 == 1 || b4 == 3)
						{
							RemoteClient remoteClient = Netplay.Clients[this.whoAmI];
							remoteClient.SpamAddBlock += 1f;
						}
					}
					if (!Netplay.Clients[this.whoAmI].TileSections[Netplay.GetSectionX(num46), Netplay.GetSectionY(num47)])
					{
						flag5 = true;
					}
				}
				if (b4 == 0)
				{
					WorldGen.KillTile(num46, num47, flag5, false, false);
				}
				if (b4 == 1)
				{
					WorldGen.PlaceTile(num46, num47, (int)num48, false, true, -1, num49);
				}
				if (b4 == 2)
				{
					WorldGen.KillWall(num46, num47, flag5);
				}
				if (b4 == 3)
				{
					WorldGen.PlaceWall(num46, num47, (int)num48, false);
				}
				if (b4 == 4)
				{
					WorldGen.KillTile(num46, num47, flag5, false, true);
				}
				if (b4 == 5)
				{
					WorldGen.PlaceWire(num46, num47);
				}
				if (b4 == 6)
				{
					WorldGen.KillWire(num46, num47);
				}
				if (b4 == 7)
				{
					WorldGen.PoundTile(num46, num47);
				}
				if (b4 == 8)
				{
					WorldGen.PlaceActuator(num46, num47);
				}
				if (b4 == 9)
				{
					WorldGen.KillActuator(num46, num47);
				}
				if (b4 == 10)
				{
					WorldGen.PlaceWire2(num46, num47);
				}
				if (b4 == 11)
				{
					WorldGen.KillWire2(num46, num47);
				}
				if (b4 == 12)
				{
					WorldGen.PlaceWire3(num46, num47);
				}
				if (b4 == 13)
				{
					WorldGen.KillWire3(num46, num47);
				}
				if (b4 == 14)
				{
					WorldGen.SlopeTile(num46, num47, (int)num48);
				}
				if (b4 == 15)
				{
					Minecart.FrameTrack(num46, num47, true, false);
				}
				if (b4 == 16)
				{
					WorldGen.PlaceWire4(num46, num47);
				}
				if (b4 == 17)
				{
					WorldGen.KillWire4(num46, num47);
				}
				if (b4 == 18)
				{
					Wiring.SetCurrentUser(this.whoAmI);
					Wiring.PokeLogicGate(num46, num47);
					Wiring.SetCurrentUser(-1);
					return;
				}
				if (b4 == 19)
				{
					Wiring.SetCurrentUser(this.whoAmI);
					Wiring.Actuate(num46, num47);
					Wiring.SetCurrentUser(-1);
					return;
				}
				if (Main.netMode != 2)
				{
					return;
				}
				NetMessage.SendData(17, -1, this.whoAmI, null, (int)b4, (float)num46, (float)num47, (float)num48, num49, 0, 0);
				if (b4 == 1 && num48 == 53)
				{
					NetMessage.SendTileSquare(-1, num46, num47, 1, TileChangeType.None);
					return;
				}
				return;
			}
			case 18:
				if (Main.netMode != 1)
				{
					return;
				}
				Main.dayTime = (this.reader.ReadByte() == 1);
				Main.time = (double)this.reader.ReadInt32();
				Main.sunModY = this.reader.ReadInt16();
				Main.moonModY = this.reader.ReadInt16();
				return;
			case 19:
			{
				byte b5 = this.reader.ReadByte();
				int num50 = (int)this.reader.ReadInt16();
				int num51 = (int)this.reader.ReadInt16();
				if (!WorldGen.InWorld(num50, num51, 3))
				{
					return;
				}
				int num52 = (this.reader.ReadByte() == 0) ? -1 : 1;
				if (b5 == 0)
				{
					WorldGen.OpenDoor(num50, num51, num52);
				}
				else if (b5 == 1)
				{
					WorldGen.CloseDoor(num50, num51, true);
				}
				else if (b5 == 2)
				{
					WorldGen.ShiftTrapdoor(num50, num51, num52 == 1, 1);
				}
				else if (b5 == 3)
				{
					WorldGen.ShiftTrapdoor(num50, num51, num52 == 1, 0);
				}
				else if (b5 == 4)
				{
					WorldGen.ShiftTallGate(num50, num51, false);
				}
				else if (b5 == 5)
				{
					WorldGen.ShiftTallGate(num50, num51, true);
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(19, -1, this.whoAmI, null, (int)b5, (float)num50, (float)num51, (float)((num52 == 1) ? 1 : 0), 0, 0, 0);
					return;
				}
				return;
			}
			case 20:
			{
				ushort num53 = this.reader.ReadUInt16();
				short num54 = (short)(num53 & 32767);
				bool flag6 = (num53 & 32768) > 0;
				byte b6 = 0;
				if (flag6)
				{
					b6 = this.reader.ReadByte();
				}
				int num55 = (int)this.reader.ReadInt16();
				int num56 = (int)this.reader.ReadInt16();
				if (!WorldGen.InWorld(num55, num56, 3))
				{
					return;
				}
				TileChangeType type3 = TileChangeType.None;
				if (Enum.IsDefined(typeof(TileChangeType), b6))
				{
					type3 = (TileChangeType)b6;
				}
				if (MessageBuffer.OnTileChangeReceived != null)
				{
					MessageBuffer.OnTileChangeReceived(num55, num56, (int)num54, type3);
				}
				BitsByte bitsByte5 = 0;
				BitsByte bitsByte6 = 0;
				for (int num57 = num55; num57 < num55 + (int)num54; num57 = num2 + 1)
				{
					for (int num58 = num56; num58 < num56 + (int)num54; num58 = num2 + 1)
					{
						if (Main.tile[num57, num58] == null)
						{
							Main.tile[num57, num58] = new Tile();
						}
						Tile tile = Main.tile[num57, num58];
						bool flag7 = tile.active();
						bitsByte5 = this.reader.ReadByte();
						bitsByte6 = this.reader.ReadByte();
						tile.active(bitsByte5[0]);
						tile.wall = (bitsByte5[2] ? 1 : 0);
						bool flag8 = bitsByte5[3];
						if (Main.netMode != 2)
						{
							tile.liquid = (flag8 ? 1 : 0);
						}
						tile.wire(bitsByte5[4]);
						tile.halfBrick(bitsByte5[5]);
						tile.actuator(bitsByte5[6]);
						tile.inActive(bitsByte5[7]);
						tile.wire2(bitsByte6[0]);
						tile.wire3(bitsByte6[1]);
						if (bitsByte6[2])
						{
							tile.color(this.reader.ReadByte());
						}
						if (bitsByte6[3])
						{
							tile.wallColor(this.reader.ReadByte());
						}
						if (tile.active())
						{
							int type4 = (int)tile.type;
							tile.type = this.reader.ReadUInt16();
							if (Main.tileFrameImportant[(int)tile.type])
							{
								tile.frameX = this.reader.ReadInt16();
								tile.frameY = this.reader.ReadInt16();
							}
							else if (!flag7 || (int)tile.type != type4)
							{
								tile.frameX = -1;
								tile.frameY = -1;
							}
							byte b7 = 0;
							if (bitsByte6[4])
							{
								b7 += 1;
							}
							if (bitsByte6[5])
							{
								b7 += 2;
							}
							if (bitsByte6[6])
							{
								b7 += 4;
							}
							tile.slope(b7);
						}
						tile.wire4(bitsByte6[7]);
						if (tile.wall > 0)
						{
							tile.wall = (ModNet.AllowVanillaClients ? ((ushort)this.reader.ReadByte()) : this.reader.ReadUInt16());
						}
						if (flag8)
						{
							tile.liquid = this.reader.ReadByte();
							tile.liquidType((int)this.reader.ReadByte());
						}
						num2 = num58;
					}
					num2 = num57;
				}
				WorldGen.RangeFrame(num55, num56, num55 + (int)num54, num56 + (int)num54);
				if (Main.netMode == 2)
				{
					NetMessage.SendData((int)b, -1, this.whoAmI, null, (int)num54, (float)num55, (float)num56, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 21:
			case 90:
			{
				int num59 = (int)this.reader.ReadInt16();
				Vector2 vector = this.reader.ReadVector2();
				Vector2 velocity = this.reader.ReadVector2();
				int stack3 = (int)this.reader.ReadInt16();
				int pre = (int)this.reader.ReadByte();
				int num60 = (int)this.reader.ReadByte();
				int num61 = (int)this.reader.ReadInt16();
				if (Main.netMode == 1)
				{
					if (num61 == 0)
					{
						Main.item[num59].active = false;
						return;
					}
					int num62 = num59;
					Item item = Main.item[num62];
					bool newAndShiny = (item.newAndShiny || item.netID != num61) && ItemSlot.Options.HighlightNewItems && (num61 < 0 || !ItemID.Sets.NeverShiny[num61]);
					item.netDefaults(num61);
					item.newAndShiny = newAndShiny;
					item.Prefix(pre);
					item.stack = stack3;
					item.position = vector;
					item.velocity = velocity;
					item.active = true;
					ItemIO.ReceiveModData(item, this.reader);
					if (b == 90)
					{
						item.instanced = true;
						item.owner = Main.myPlayer;
						item.keepTime = 600;
					}
					item.wet = Collision.WetCollision(item.position, item.width, item.height);
					return;
				}
				else
				{
					if (Main.itemLockoutTime[num59] > 0)
					{
						return;
					}
					if (num61 == 0)
					{
						if (num59 < 400)
						{
							Main.item[num59].active = false;
							NetMessage.SendData(21, -1, -1, null, num59, 0f, 0f, 0f, 0, 0, 0);
							return;
						}
						return;
					}
					else
					{
						bool flag9 = false;
						if (num59 == 400)
						{
							flag9 = true;
						}
						if (flag9)
						{
							Item item2 = new Item();
							item2.netDefaults(num61);
							num59 = Item.NewItem((int)vector.X, (int)vector.Y, item2.width, item2.height, item2.type, stack3, true, 0, false, false);
						}
						Item item3 = Main.item[num59];
						item3.netDefaults(num61);
						item3.Prefix(pre);
						item3.stack = stack3;
						item3.position = vector;
						item3.velocity = velocity;
						item3.active = true;
						ItemIO.ReceiveModData(item3, this.reader);
						item3.owner = Main.myPlayer;
						if (flag9)
						{
							NetMessage.SendData(21, -1, -1, null, num59, 0f, 0f, 0f, 0, 0, 0);
							if (num60 == 0)
							{
								Main.item[num59].ownIgnore = this.whoAmI;
								Main.item[num59].ownTime = 100;
							}
							Main.item[num59].FindOwner(num59);
							return;
						}
						NetMessage.SendData(21, -1, this.whoAmI, null, num59, 0f, 0f, 0f, 0, 0, 0);
						return;
					}
				}
				break;
			}
			case 22:
			{
				int num63 = (int)this.reader.ReadInt16();
				int num64 = (int)this.reader.ReadByte();
				if (Main.netMode == 2 && Main.item[num63].owner != this.whoAmI)
				{
					return;
				}
				Main.item[num63].owner = num64;
				if (num64 == Main.myPlayer)
				{
					Main.item[num63].keepTime = 15;
				}
				else
				{
					Main.item[num63].keepTime = 0;
				}
				if (Main.netMode == 2)
				{
					Main.item[num63].owner = 255;
					Main.item[num63].keepTime = 15;
					NetMessage.SendData(22, -1, -1, null, num63, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 23:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num65 = (int)this.reader.ReadInt16();
				Vector2 vector2 = this.reader.ReadVector2();
				Vector2 velocity2 = this.reader.ReadVector2();
				int target = (int)this.reader.ReadUInt16();
				BitsByte bitsByte7 = this.reader.ReadByte();
				float[] array2 = new float[NPC.maxAI];
				for (int num66 = 0; num66 < NPC.maxAI; num66 = num2 + 1)
				{
					if (bitsByte7[num66 + 2])
					{
						array2[num66] = this.reader.ReadSingle();
					}
					else
					{
						array2[num66] = 0f;
					}
					num2 = num66;
				}
				int num67 = (int)this.reader.ReadInt16();
				int num68 = 0;
				if (!bitsByte7[7])
				{
					byte b8 = this.reader.ReadByte();
					if (b8 == 2)
					{
						num68 = (int)this.reader.ReadInt16();
					}
					else if (b8 == 4)
					{
						num68 = this.reader.ReadInt32();
					}
					else
					{
						num68 = (int)this.reader.ReadSByte();
					}
				}
				int num69 = -1;
				NPC npc = Main.npc[num65];
				if (!npc.active || npc.netID != num67)
				{
					if (npc.active)
					{
						num69 = npc.type;
					}
					npc.active = true;
					npc.SetDefaults(num67, -1f);
				}
				if (Vector2.DistanceSquared(npc.position, vector2) < 6400f)
				{
					npc.visualOffset = npc.position - vector2;
				}
				npc.position = vector2;
				npc.velocity = velocity2;
				npc.target = target;
				npc.direction = (bitsByte7[0] ? 1 : -1);
				npc.directionY = (bitsByte7[1] ? 1 : -1);
				npc.spriteDirection = (bitsByte7[6] ? 1 : -1);
				if (bitsByte7[7])
				{
					num68 = (npc.life = npc.lifeMax);
				}
				else
				{
					npc.life = num68;
				}
				if (num68 <= 0)
				{
					npc.active = false;
				}
				for (int num70 = 0; num70 < NPC.maxAI; num70 = num2 + 1)
				{
					npc.ai[num70] = array2[num70];
					num2 = num70;
				}
				if (num69 > -1 && num69 != npc.type)
				{
					npc.TransformVisuals(num69, npc.type);
				}
				if (num67 == 262)
				{
					NPC.plantBoss = num65;
				}
				if (num67 == 245)
				{
					NPC.golemBoss = num65;
				}
				if (npc.type >= 0 && npc.type < NPCLoader.NPCCount && Main.npcCatchable[npc.type])
				{
					npc.releaseOwner = (short)this.reader.ReadByte();
				}
				NPCLoader.ReceiveExtraAI(npc, this.reader);
				return;
			}
			case 24:
			{
				int num71 = (int)this.reader.ReadInt16();
				int num72 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num72 = this.whoAmI;
				}
				Player player10 = Main.player[num72];
				Main.npc[num71].StrikeNPC(player10.inventory[player10.selectedItem].damage, player10.inventory[player10.selectedItem].knockBack, player10.direction, false, false, false);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(24, -1, this.whoAmI, null, num71, (float)num72, 0f, 0f, 0, 0, 0);
					NetMessage.SendData(23, -1, -1, null, num71, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 27:
			{
				int num73 = (int)this.reader.ReadInt16();
				Vector2 position = this.reader.ReadVector2();
				Vector2 velocity3 = this.reader.ReadVector2();
				float knockBack = this.reader.ReadSingle();
				int damage = (int)this.reader.ReadInt16();
				int num74 = (int)this.reader.ReadByte();
				int num75 = (int)this.reader.ReadInt16();
				BitsByte flags = this.reader.ReadByte();
				float[] array3 = new float[Projectile.maxAI];
				for (int num76 = 0; num76 < Projectile.maxAI; num76 = num2 + 1)
				{
					if (flags[num76])
					{
						array3[num76] = this.reader.ReadSingle();
					}
					else
					{
						array3[num76] = 0f;
					}
					num2 = num76;
				}
				int num77 = (int)(flags[Projectile.maxAI] ? this.reader.ReadInt16() : -1);
				if (num77 >= 1000)
				{
					num77 = -1;
				}
				byte[] extraAI = ProjectileLoader.ReadExtraAI(this.reader, flags);
				if (Main.netMode == 2)
				{
					num74 = this.whoAmI;
					if (Main.projHostile[num75])
					{
						return;
					}
				}
				int num78 = 1000;
				for (int num79 = 0; num79 < 1000; num79 = num2 + 1)
				{
					if (Main.projectile[num79].owner == num74 && Main.projectile[num79].identity == num73 && Main.projectile[num79].active)
					{
						num78 = num79;
						break;
					}
					num2 = num79;
				}
				if (num78 == 1000)
				{
					for (int num80 = 0; num80 < 1000; num80 = num2 + 1)
					{
						if (!Main.projectile[num80].active)
						{
							num78 = num80;
							break;
						}
						num2 = num80;
					}
				}
				Projectile projectile = Main.projectile[num78];
				if (!projectile.active || projectile.type != num75)
				{
					projectile.SetDefaults(num75);
					if (Main.netMode == 2)
					{
						RemoteClient remoteClient = Netplay.Clients[this.whoAmI];
						remoteClient.SpamProjectile += 1f;
					}
				}
				projectile.identity = num73;
				projectile.position = position;
				projectile.velocity = velocity3;
				projectile.type = num75;
				projectile.damage = damage;
				projectile.knockBack = knockBack;
				projectile.owner = num74;
				for (int num81 = 0; num81 < Projectile.maxAI; num81 = num2 + 1)
				{
					projectile.ai[num81] = array3[num81];
					num2 = num81;
				}
				if (num77 >= 0)
				{
					projectile.projUUID = num77;
					Main.projectileIdentity[num74, num77] = num78;
				}
				ProjectileLoader.ReceiveExtraAI(projectile, extraAI);
				projectile.ProjectileFixDesperation();
				if (Main.netMode == 2)
				{
					NetMessage.SendData(27, -1, this.whoAmI, null, num78, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 28:
			{
				int num82 = (int)this.reader.ReadInt16();
				int num83 = (int)this.reader.ReadInt16();
				float num84 = this.reader.ReadSingle();
				int num85 = (int)(this.reader.ReadByte() - 1);
				byte b9 = this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					if (num83 < 0)
					{
						num83 = 0;
					}
					Main.npc[num82].PlayerInteraction(this.whoAmI);
				}
				if (num83 >= 0)
				{
					Main.npc[num82].StrikeNPC(num83, num84, num85, b9 == 1, false, true);
				}
				else
				{
					Main.npc[num82].life = 0;
					Main.npc[num82].HitEffect(0, 10.0);
					Main.npc[num82].active = false;
				}
				if (Main.netMode != 2)
				{
					return;
				}
				NetMessage.SendData(28, -1, this.whoAmI, null, num82, (float)num83, num84, (float)num85, (int)b9, 0, 0);
				if (Main.npc[num82].life <= 0)
				{
					NetMessage.SendData(23, -1, -1, null, num82, 0f, 0f, 0f, 0, 0, 0);
				}
				else
				{
					Main.npc[num82].netUpdate = true;
				}
				if (Main.npc[num82].realLife < 0)
				{
					return;
				}
				if (Main.npc[Main.npc[num82].realLife].life <= 0)
				{
					NetMessage.SendData(23, -1, -1, null, Main.npc[num82].realLife, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				Main.npc[Main.npc[num82].realLife].netUpdate = true;
				return;
			}
			case 29:
			{
				int num86 = (int)this.reader.ReadInt16();
				int num87 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num87 = this.whoAmI;
				}
				for (int num88 = 0; num88 < 1000; num88 = num2 + 1)
				{
					if (Main.projectile[num88].owner == num87 && Main.projectile[num88].identity == num86 && Main.projectile[num88].active)
					{
						Main.projectile[num88].Kill();
						break;
					}
					num2 = num88;
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(29, -1, this.whoAmI, null, num86, (float)num87, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 30:
			{
				int num89 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num89 = this.whoAmI;
				}
				bool flag10 = this.reader.ReadBoolean();
				Main.player[num89].hostile = flag10;
				if (Main.netMode == 2)
				{
					NetMessage.SendData(30, -1, this.whoAmI, null, num89, 0f, 0f, 0f, 0, 0, 0);
					LocalizedText localizedText = flag10 ? Lang.mp[11] : Lang.mp[12];
					Color color = Main.teamColor[Main.player[num89].team];
					NetMessage.BroadcastChatMessage(NetworkText.FromKey(localizedText.Key, new object[]
					{
						Main.player[num89].name
					}), color, -1);
					return;
				}
				return;
			}
			case 31:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int x = (int)this.reader.ReadInt16();
				int y = (int)this.reader.ReadInt16();
				int num90 = Chest.FindChest(x, y);
				if (num90 > -1 && Chest.UsingChest(num90) == -1)
				{
					for (int num91 = 0; num91 < 40; num91 = num2 + 1)
					{
						NetMessage.SendData(32, this.whoAmI, -1, null, num90, (float)num91, 0f, 0f, 0, 0, 0);
						num2 = num91;
					}
					NetMessage.SendData(33, this.whoAmI, -1, null, num90, 0f, 0f, 0f, 0, 0, 0);
					Main.player[this.whoAmI].chest = num90;
					if (Main.myPlayer == this.whoAmI)
					{
						Main.recBigList = false;
					}
					NetMessage.SendData(80, -1, this.whoAmI, null, this.whoAmI, (float)num90, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 32:
			{
				int num92 = (int)this.reader.ReadInt16();
				int num93 = (int)this.reader.ReadByte();
				int stack4 = (int)this.reader.ReadInt16();
				int pre2 = (int)this.reader.ReadByte();
				int type5 = (int)this.reader.ReadInt16();
				if (Main.chest[num92] == null)
				{
					Main.chest[num92] = new Chest(false);
				}
				if (Main.chest[num92].item[num93] == null)
				{
					Main.chest[num92].item[num93] = new Item();
				}
				Main.chest[num92].item[num93].netDefaults(type5);
				Main.chest[num92].item[num93].Prefix(pre2);
				Main.chest[num92].item[num93].stack = stack4;
				ItemIO.ReceiveModData(Main.chest[num92].item[num93], this.reader);
				Recipe.FindRecipes();
				return;
			}
			case 33:
			{
				int num94 = (int)this.reader.ReadInt16();
				int num95 = (int)this.reader.ReadInt16();
				int num96 = (int)this.reader.ReadInt16();
				int num97 = (int)this.reader.ReadByte();
				string name = string.Empty;
				if (num97 != 0)
				{
					if (num97 <= 20)
					{
						name = this.reader.ReadString();
					}
					else if (num97 != 255)
					{
						num97 = 0;
					}
				}
				if (Main.netMode != 1)
				{
					if (num97 != 0)
					{
						int chest = Main.player[this.whoAmI].chest;
						Chest chest2 = Main.chest[chest];
						chest2.name = name;
						NetMessage.SendData(69, -1, this.whoAmI, null, chest, (float)chest2.x, (float)chest2.y, 0f, 0, 0, 0);
					}
					Main.player[this.whoAmI].chest = num94;
					Recipe.FindRecipes();
					NetMessage.SendData(80, -1, this.whoAmI, null, this.whoAmI, (float)num94, 0f, 0f, 0, 0, 0);
					return;
				}
				Player player11 = Main.player[Main.myPlayer];
				if (player11.chest == -1)
				{
					Main.playerInventory = true;
					Main.PlaySound(10, -1, -1, 1, 1f, 0f);
				}
				else if (player11.chest != num94 && num94 != -1)
				{
					Main.playerInventory = true;
					Main.PlaySound(12, -1, -1, 1, 1f, 0f);
					Main.recBigList = false;
				}
				else if (player11.chest != -1 && num94 == -1)
				{
					Main.PlaySound(11, -1, -1, 1, 1f, 0f);
					Main.recBigList = false;
				}
				player11.chest = num94;
				player11.chestX = num95;
				player11.chestY = num96;
				Recipe.FindRecipes();
				if (Main.tile[num95, num96].frameX >= 36 && Main.tile[num95, num96].frameX < 72)
				{
					AchievementsHelper.HandleSpecialEvent(Main.player[Main.myPlayer], 16);
					return;
				}
				return;
			}
			case 34:
			{
				byte b10 = this.reader.ReadByte();
				int num98 = (int)this.reader.ReadInt16();
				int num99 = (int)this.reader.ReadInt16();
				int num100 = (int)this.reader.ReadInt16();
				int num101 = (int)this.reader.ReadInt16();
				if (Main.netMode == 2)
				{
					num101 = 0;
				}
				ushort num102 = 0;
				if (b10 >= 100)
				{
					num102 = this.reader.ReadUInt16();
				}
				if (Main.netMode == 2)
				{
					if (b10 % 100 == 0)
					{
						if (num102 == 0)
						{
							num102 = 21;
						}
						int num103 = WorldGen.PlaceChest(num98, num99, num102, false, num100);
						if (num103 == -1)
						{
							NetMessage.SendData(34, this.whoAmI, -1, null, (int)b10, (float)num98, (float)num99, (float)num100, num103, (int)num102, 0);
							int num104 = (b10 < 100) ? Chest.chestItemSpawn[num100] : TileLoader.GetTile((int)num102).chestDrop;
							if (num104 > 0)
							{
								Item.NewItem(num98 * 16, num99 * 16, 32, 32, num104, 1, true, 0, false, false);
							}
							return;
						}
						NetMessage.SendData(34, -1, -1, null, (int)b10, (float)num98, (float)num99, (float)num100, num103, (int)num102, 0);
						return;
					}
					else if ((b10 == 1 && Main.tile[num98, num99].type == 21) || (b10 == 101 && TileID.Sets.BasicChest[(int)Main.tile[num98, num99].type]))
					{
						Tile tile2 = Main.tile[num98, num99];
						if (tile2.frameX % 36 != 0)
						{
							num2 = num98;
							num98 = num2 - 1;
						}
						if (tile2.frameY % 36 != 0)
						{
							num2 = num99;
							num99 = num2 - 1;
						}
						int number = Chest.FindChest(num98, num99);
						WorldGen.KillTile(num98, num99, false, false, false);
						if (!tile2.active())
						{
							NetMessage.SendData(34, -1, -1, null, (int)b10, (float)num98, (float)num99, 0f, number, 0, 0);
							return;
						}
						return;
					}
					else if (b10 % 100 == 2)
					{
						if (num102 == 0)
						{
							num102 = 88;
						}
						int num105 = WorldGen.PlaceChest(num98, num99, num102, false, num100);
						if (num105 == -1)
						{
							NetMessage.SendData(34, this.whoAmI, -1, null, (int)b10, (float)num98, (float)num99, (float)num100, num105, (int)num102, 0);
							int num106 = (b10 < 100) ? Chest.dresserItemSpawn[num100] : TileLoader.GetTile((int)num102).dresserDrop;
							if (num106 > 0)
							{
								Item.NewItem(num98 * 16, num99 * 16, 32, 32, num106, 1, true, 0, false, false);
							}
							return;
						}
						NetMessage.SendData(34, -1, -1, null, (int)b10, (float)num98, (float)num99, (float)num100, num105, (int)num102, 0);
						return;
					}
					else if ((b10 == 3 && Main.tile[num98, num99].type == 88) || (b10 == 103 && TileLoader.IsDresser((int)Main.tile[num98, num99].type)))
					{
						Tile tile3 = Main.tile[num98, num99];
						num98 -= (int)(tile3.frameX % 54 / 18);
						if (tile3.frameY % 36 != 0)
						{
							num2 = num99;
							num99 = num2 - 1;
						}
						int number2 = Chest.FindChest(num98, num99);
						WorldGen.KillTile(num98, num99, false, false, false);
						if (!tile3.active())
						{
							NetMessage.SendData(34, -1, -1, null, (int)b10, (float)num98, (float)num99, 0f, number2, 0, 0);
							return;
						}
						return;
					}
					else if (b10 == 4)
					{
						int num107 = WorldGen.PlaceChest(num98, num99, 467, false, num100);
						if (num107 == -1)
						{
							NetMessage.SendData(34, this.whoAmI, -1, null, (int)b10, (float)num98, (float)num99, (float)num100, num107, 0, 0);
							Item.NewItem(num98 * 16, num99 * 16, 32, 32, Chest.chestItemSpawn2[num100], 1, true, 0, false, false);
							return;
						}
						NetMessage.SendData(34, -1, -1, null, (int)b10, (float)num98, (float)num99, (float)num100, num107, 0, 0);
						return;
					}
					else
					{
						if (b10 != 5 || Main.tile[num98, num99].type != 467)
						{
							return;
						}
						Tile tile4 = Main.tile[num98, num99];
						if (tile4.frameX % 36 != 0)
						{
							num2 = num98;
							num98 = num2 - 1;
						}
						if (tile4.frameY % 36 != 0)
						{
							num2 = num99;
							num99 = num2 - 1;
						}
						int number3 = Chest.FindChest(num98, num99);
						WorldGen.KillTile(num98, num99, false, false, false);
						if (!tile4.active())
						{
							NetMessage.SendData(34, -1, -1, null, (int)b10, (float)num98, (float)num99, 0f, number3, 0, 0);
							return;
						}
						return;
					}
				}
				else if (b10 % 100 == 0)
				{
					if (num101 == -1)
					{
						WorldGen.KillTile(num98, num99, false, false, false);
						return;
					}
					if (num102 == 0)
					{
						num102 = 21;
					}
					WorldGen.PlaceChestDirect(num98, num99, num102, num100, num101);
					return;
				}
				else if (b10 % 100 == 2)
				{
					if (num101 == -1)
					{
						WorldGen.KillTile(num98, num99, false, false, false);
						return;
					}
					if (num102 == 0)
					{
						num102 = 88;
					}
					WorldGen.PlaceDresserDirect(num98, num99, num102, num100, num101);
					return;
				}
				else
				{
					if (b10 != 4)
					{
						Chest.DestroyChestDirect(num98, num99, num101);
						WorldGen.KillTile(num98, num99, false, false, false);
						return;
					}
					if (num101 == -1)
					{
						WorldGen.KillTile(num98, num99, false, false, false);
						return;
					}
					WorldGen.PlaceChestDirect(num98, num99, 467, num100, num101);
					return;
				}
				break;
			}
			case 35:
			{
				int num108 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num108 = this.whoAmI;
				}
				int num109 = (int)this.reader.ReadInt16();
				if (num108 != Main.myPlayer || Main.ServerSideCharacter)
				{
					Main.player[num108].HealEffect(num109, true);
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(35, -1, this.whoAmI, null, num108, (float)num109, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 36:
			{
				int num110 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num110 = this.whoAmI;
				}
				Player player12 = Main.player[num110];
				player12.zone1 = this.reader.ReadByte();
				player12.zone2 = this.reader.ReadByte();
				player12.zone3 = this.reader.ReadByte();
				player12.zone4 = this.reader.ReadByte();
				if (!ModNet.AllowVanillaClients)
				{
					PlayerHooks.ReceiveCustomBiomes(player12, this.reader);
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(36, -1, this.whoAmI, null, num110, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 37:
				if (Main.netMode != 1)
				{
					return;
				}
				if (Main.autoPass)
				{
					NetMessage.SendData(38, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
					Main.autoPass = false;
					return;
				}
				Netplay.ServerPassword = "";
				Main.menuMode = 31;
				return;
			case 38:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				string a = this.reader.ReadString();
				if (!(a == Netplay.ServerPassword))
				{
					NetMessage.SendData(2, this.whoAmI, -1, Lang.mp[1].ToNetworkText(), 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				Netplay.Clients[this.whoAmI].State = 1;
				if (ModNet.isModdedClient[this.whoAmI])
				{
					ModNet.SyncMods(this.whoAmI);
					return;
				}
				NetMessage.SendData(3, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			case 39:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num111 = (int)this.reader.ReadInt16();
				Main.item[num111].owner = 255;
				NetMessage.SendData(22, -1, -1, null, num111, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			case 40:
			{
				int num112 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num112 = this.whoAmI;
				}
				int talkNPC = (int)this.reader.ReadInt16();
				Main.player[num112].talkNPC = talkNPC;
				if (Main.netMode == 2)
				{
					NetMessage.SendData(40, -1, this.whoAmI, null, num112, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 41:
			{
				int num113 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num113 = this.whoAmI;
				}
				Player player13 = Main.player[num113];
				float itemRotation = this.reader.ReadSingle();
				int itemAnimation = (int)this.reader.ReadInt16();
				player13.itemRotation = itemRotation;
				player13.itemAnimation = itemAnimation;
				player13.channel = player13.inventory[player13.selectedItem].channel;
				if (Main.netMode == 2)
				{
					NetMessage.SendData(41, -1, this.whoAmI, null, num113, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 42:
			{
				int num114 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num114 = this.whoAmI;
				}
				else if (Main.myPlayer == num114 && !Main.ServerSideCharacter)
				{
					return;
				}
				int statMana = (int)this.reader.ReadInt16();
				int statManaMax = (int)this.reader.ReadInt16();
				Main.player[num114].statMana = statMana;
				Main.player[num114].statManaMax = statManaMax;
				return;
			}
			case 43:
			{
				int num115 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num115 = this.whoAmI;
				}
				int num116 = (int)this.reader.ReadInt16();
				if (num115 != Main.myPlayer)
				{
					Main.player[num115].ManaEffect(num116);
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(43, -1, this.whoAmI, null, num115, (float)num116, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 45:
			{
				int num117 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num117 = this.whoAmI;
				}
				int num118 = (int)this.reader.ReadByte();
				Player player14 = Main.player[num117];
				int team = player14.team;
				player14.team = num118;
				Color color2 = Main.teamColor[num118];
				if (Main.netMode == 2)
				{
					NetMessage.SendData(45, -1, this.whoAmI, null, num117, 0f, 0f, 0f, 0, 0, 0);
					LocalizedText localizedText2 = Lang.mp[13 + num118];
					if (num118 == 5)
					{
						localizedText2 = Lang.mp[22];
					}
					for (int num119 = 0; num119 < 255; num119 = num2 + 1)
					{
						if (num119 == this.whoAmI || (team > 0 && Main.player[num119].team == team) || (num118 > 0 && Main.player[num119].team == num118))
						{
							NetMessage.SendChatMessageToClient(NetworkText.FromKey(localizedText2.Key, new object[]
							{
								player14.name
							}), color2, num119);
						}
						num2 = num119;
					}
					return;
				}
				return;
			}
			case 46:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int i2 = (int)this.reader.ReadInt16();
				int j2 = (int)this.reader.ReadInt16();
				int num120 = Sign.ReadSign(i2, j2, true);
				if (num120 >= 0)
				{
					NetMessage.SendData(47, this.whoAmI, -1, null, num120, (float)this.whoAmI, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 47:
			{
				int num121 = (int)this.reader.ReadInt16();
				int x2 = (int)this.reader.ReadInt16();
				int y2 = (int)this.reader.ReadInt16();
				string text2 = this.reader.ReadString();
				string a2 = null;
				if (Main.sign[num121] != null)
				{
					a2 = Main.sign[num121].text;
				}
				Main.sign[num121] = new Sign();
				Main.sign[num121].x = x2;
				Main.sign[num121].y = y2;
				Sign.TextSign(num121, text2);
				int num122 = (int)this.reader.ReadByte();
				if (Main.netMode == 2 && a2 != text2)
				{
					num122 = this.whoAmI;
					NetMessage.SendData(47, -1, this.whoAmI, null, num121, (float)num122, 0f, 0f, 0, 0, 0);
				}
				if (Main.netMode == 1 && num122 == Main.myPlayer && Main.sign[num121] != null)
				{
					Main.playerInventory = false;
					Main.player[Main.myPlayer].talkNPC = -1;
					Main.npcChatCornerItem = 0;
					Main.editSign = false;
					Main.PlaySound(10, -1, -1, 1, 1f, 0f);
					Main.player[Main.myPlayer].sign = num121;
					Main.npcChatText = Main.sign[num121].text;
					return;
				}
				return;
			}
			case 48:
			{
				int num123 = (int)this.reader.ReadInt16();
				int num124 = (int)this.reader.ReadInt16();
				byte liquid = this.reader.ReadByte();
				byte liquidType = this.reader.ReadByte();
				if (Main.netMode == 2 && Netplay.spamCheck)
				{
					int num125 = this.whoAmI;
					int num126 = (int)(Main.player[num125].position.X + (float)(Main.player[num125].width / 2));
					int num127 = (int)(Main.player[num125].position.Y + (float)(Main.player[num125].height / 2));
					int num128 = 10;
					int num129 = num126 - num128;
					int num130 = num126 + num128;
					int num131 = num127 - num128;
					int num132 = num127 + num128;
					if (num123 < num129 || num123 > num130 || num124 < num131 || num124 > num132)
					{
						NetMessage.BootPlayer(this.whoAmI, NetworkText.FromKey("Net.CheatingLiquidSpam", new object[0]));
						return;
					}
				}
				if (Main.tile[num123, num124] == null)
				{
					Main.tile[num123, num124] = new Tile();
				}
				Tile obj2 = Main.tile[num123, num124];
				lock (obj2)
				{
					Main.tile[num123, num124].liquid = liquid;
					Main.tile[num123, num124].liquidType((int)liquidType);
					if (Main.netMode == 2)
					{
						WorldGen.SquareTileFrame(num123, num124, true);
					}
					return;
				}
				goto IL_4A71;
			}
			case 49:
				if (Netplay.Connection.State == 6)
				{
					Netplay.Connection.State = 10;
					Main.ActivePlayerFileData.StartPlayTimer();
					Player.Hooks.EnterWorld(Main.myPlayer);
					Main.player[Main.myPlayer].Spawn();
					return;
				}
				return;
			case 50:
				goto IL_4A71;
			case 51:
			{
				byte b11 = this.reader.ReadByte();
				byte b12 = this.reader.ReadByte();
				if (b12 == 1)
				{
					NPC.SpawnSkeletron();
					return;
				}
				if (b12 == 2)
				{
					if (Main.netMode == 2)
					{
						NetMessage.SendData(51, -1, this.whoAmI, null, (int)b11, (float)b12, 0f, 0f, 0, 0, 0);
						return;
					}
					Main.PlaySound(SoundID.Item1, (int)Main.player[(int)b11].position.X, (int)Main.player[(int)b11].position.Y);
					return;
				}
				else if (b12 == 3)
				{
					if (Main.netMode == 2)
					{
						Main.Sundialing();
						return;
					}
					return;
				}
				else
				{
					if (b12 == 4)
					{
						Main.npc[(int)b11].BigMimicSpawnSmoke();
						return;
					}
					return;
				}
				break;
			}
			case 52:
			{
				int num133 = (int)this.reader.ReadByte();
				int num134 = (int)this.reader.ReadInt16();
				int num135 = (int)this.reader.ReadInt16();
				if (num133 == 1)
				{
					Chest.Unlock(num134, num135);
					if (Main.netMode == 2)
					{
						NetMessage.SendData(52, -1, this.whoAmI, null, 0, (float)num133, (float)num134, (float)num135, 0, 0, 0);
						NetMessage.SendTileSquare(-1, num134, num135, 2, TileChangeType.None);
					}
				}
				if (num133 != 2)
				{
					return;
				}
				WorldGen.UnlockDoor(num134, num135);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(52, -1, this.whoAmI, null, 0, (float)num133, (float)num134, (float)num135, 0, 0, 0);
					NetMessage.SendTileSquare(-1, num134, num135, 2, TileChangeType.None);
					return;
				}
				return;
			}
			case 53:
			{
				int num136 = (int)this.reader.ReadInt16();
				int type6 = (int)(ModNet.AllowVanillaClients ? ((ushort)this.reader.ReadByte()) : this.reader.ReadUInt16());
				int time = (int)this.reader.ReadInt16();
				Main.npc[num136].AddBuff(type6, time, true);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(54, -1, -1, null, num136, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 54:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num137 = (int)this.reader.ReadInt16();
				NPC npc2 = Main.npc[num137];
				for (int num138 = 0; num138 < 5; num138 = num2 + 1)
				{
					npc2.buffType[num138] = (int)(ModNet.AllowVanillaClients ? ((ushort)this.reader.ReadByte()) : this.reader.ReadUInt16());
					npc2.buffTime[num138] = (int)this.reader.ReadInt16();
					num2 = num138;
				}
				return;
			}
			case 55:
			{
				int num139 = (int)this.reader.ReadByte();
				int num140 = (int)(ModNet.AllowVanillaClients ? ((ushort)this.reader.ReadByte()) : this.reader.ReadUInt16());
				int num141 = this.reader.ReadInt32();
				if (Main.netMode == 2 && num139 != this.whoAmI && !Main.pvpBuff[num140])
				{
					return;
				}
				if (Main.netMode == 1 && num139 == Main.myPlayer)
				{
					Main.player[num139].AddBuff(num140, num141, true);
					return;
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(55, num139, -1, null, num139, (float)num140, (float)num141, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 56:
			{
				int num142 = (int)this.reader.ReadInt16();
				if (num142 < 0 || num142 >= 200)
				{
					return;
				}
				if (Main.netMode == 1)
				{
					string givenName = this.reader.ReadString();
					Main.npc[num142].GivenName = givenName;
					return;
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(56, this.whoAmI, -1, null, num142, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 57:
				if (Main.netMode != 1)
				{
					return;
				}
				WorldGen.tGood = this.reader.ReadByte();
				WorldGen.tEvil = this.reader.ReadByte();
				WorldGen.tBlood = this.reader.ReadByte();
				return;
			case 58:
			{
				int num143 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num143 = this.whoAmI;
				}
				float num144 = this.reader.ReadSingle();
				if (Main.netMode == 2)
				{
					NetMessage.SendData(58, -1, this.whoAmI, null, this.whoAmI, num144, 0f, 0f, 0, 0, 0);
					return;
				}
				Player player15 = Main.player[num143];
				Main.harpNote = num144;
				LegacySoundStyle type7 = SoundID.Item26;
				if (player15.inventory[player15.selectedItem].type == 507)
				{
					type7 = SoundID.Item35;
				}
				Main.PlaySound(type7, player15.position);
				return;
			}
			case 59:
			{
				int num145 = (int)this.reader.ReadInt16();
				int num146 = (int)this.reader.ReadInt16();
				Wiring.SetCurrentUser(this.whoAmI);
				Wiring.HitSwitch(num145, num146);
				Wiring.SetCurrentUser(-1);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(59, -1, this.whoAmI, null, num145, (float)num146, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 60:
			{
				int num147 = (int)this.reader.ReadInt16();
				int num148 = (int)this.reader.ReadInt16();
				int num149 = (int)this.reader.ReadInt16();
				byte b13 = this.reader.ReadByte();
				if (num147 >= 200)
				{
					NetMessage.BootPlayer(this.whoAmI, NetworkText.FromKey("Net.CheatingInvalid", new object[0]));
					return;
				}
				if (Main.netMode == 1)
				{
					Main.npc[num147].homeless = (b13 == 1);
					Main.npc[num147].homeTileX = num148;
					Main.npc[num147].homeTileY = num149;
					if (b13 == 1)
					{
						WorldGen.TownManager.KickOut(Main.npc[num147].type);
						return;
					}
					if (b13 == 2)
					{
						WorldGen.TownManager.SetRoom(Main.npc[num147].type, num148, num149);
						return;
					}
					return;
				}
				else
				{
					if (b13 == 1)
					{
						WorldGen.kickOut(num147);
						return;
					}
					WorldGen.moveRoom(num148, num149, num147);
					return;
				}
				break;
			}
			case 61:
			{
				int plr = (int)this.reader.ReadInt16();
				int num150 = (int)this.reader.ReadInt16();
				if (Main.netMode != 2)
				{
					return;
				}
				if (num150 >= 0 && num150 < 580 && NPCID.Sets.MPAllowedEnemies[num150])
				{
					bool flag12 = !NPC.AnyNPCs(num150);
					if (flag12)
					{
						NPC.SpawnOnPlayer(plr, num150);
						return;
					}
					return;
				}
				else if (num150 == -4)
				{
					if (!Main.dayTime && !DD2Event.Ongoing)
					{
						NetMessage.BroadcastChatMessage(NetworkText.FromKey(Lang.misc[31].Key, new object[0]), new Color(50, 255, 130), -1);
						Main.startPumpkinMoon();
						NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
						NetMessage.SendData(78, -1, -1, null, 0, 1f, 2f, 1f, 0, 0, 0);
						return;
					}
					return;
				}
				else if (num150 == -5)
				{
					if (!Main.dayTime && !DD2Event.Ongoing)
					{
						NetMessage.BroadcastChatMessage(NetworkText.FromKey(Lang.misc[34].Key, new object[0]), new Color(50, 255, 130), -1);
						Main.startSnowMoon();
						NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
						NetMessage.SendData(78, -1, -1, null, 0, 1f, 1f, 1f, 0, 0, 0);
						return;
					}
					return;
				}
				else if (num150 == -6)
				{
					if (Main.dayTime && !Main.eclipse)
					{
						NetMessage.BroadcastChatMessage(NetworkText.FromKey(Lang.misc[20].Key, new object[0]), new Color(50, 255, 130), -1);
						Main.eclipse = true;
						NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
						return;
					}
					return;
				}
				else
				{
					if (num150 == -7)
					{
						Main.invasionDelay = 0;
						Main.StartInvasion(4);
						NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
						NetMessage.SendData(78, -1, -1, null, 0, 1f, (float)(Main.invasionType + 3), 0f, 0, 0, 0);
						return;
					}
					if (num150 == -8)
					{
						if (NPC.downedGolemBoss && Main.hardMode && !NPC.AnyDanger() && !NPC.AnyoneNearCultists())
						{
							WorldGen.StartImpendingDoom();
							NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
							return;
						}
						return;
					}
					else
					{
						if (num150 < 0)
						{
							int num151 = 1;
							if (num150 > -5)
							{
								num151 = -num150;
							}
							if (num151 > 0 && Main.invasionType == 0)
							{
								Main.invasionDelay = 0;
								Main.StartInvasion(num151);
							}
							NetMessage.SendData(78, -1, -1, null, 0, 1f, (float)(Main.invasionType + 3), 0f, 0, 0, 0);
							return;
						}
						return;
					}
				}
				break;
			}
			case 62:
			{
				int num152 = (int)this.reader.ReadByte();
				int num153 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num152 = this.whoAmI;
				}
				if (num153 == 1)
				{
					Main.player[num152].NinjaDodge();
				}
				if (num153 == 2)
				{
					Main.player[num152].ShadowDodge();
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(62, -1, this.whoAmI, null, num152, (float)num153, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 63:
			{
				int num154 = (int)this.reader.ReadInt16();
				int num155 = (int)this.reader.ReadInt16();
				byte b14 = this.reader.ReadByte();
				WorldGen.paintTile(num154, num155, b14, false);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(63, -1, this.whoAmI, null, num154, (float)num155, (float)b14, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 64:
			{
				int num156 = (int)this.reader.ReadInt16();
				int num157 = (int)this.reader.ReadInt16();
				byte b15 = this.reader.ReadByte();
				WorldGen.paintWall(num156, num157, b15, false);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(64, -1, this.whoAmI, null, num156, (float)num157, (float)b15, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 65:
			{
				BitsByte bitsByte8 = this.reader.ReadByte();
				int num158 = (int)this.reader.ReadInt16();
				if (Main.netMode == 2)
				{
					num158 = this.whoAmI;
				}
				Vector2 vector3 = this.reader.ReadVector2();
				int num159 = 0;
				int num160 = 0;
				if (bitsByte8[0])
				{
					num2 = num159;
					num159 = num2 + 1;
				}
				if (bitsByte8[1])
				{
					num159 += 2;
				}
				if (bitsByte8[2])
				{
					num2 = num160;
					num160 = num2 + 1;
				}
				if (bitsByte8[3])
				{
					num160 += 2;
				}
				if (num159 == 0)
				{
					Main.player[num158].Teleport(vector3, num160, 0);
				}
				else if (num159 == 1)
				{
					Main.npc[num158].Teleport(vector3, num160, 0);
				}
				else if (num159 == 2)
				{
					Main.player[num158].Teleport(vector3, num160, 0);
					if (Main.netMode == 2)
					{
						RemoteClient.CheckSection(this.whoAmI, vector3, 1);
						NetMessage.SendData(65, -1, -1, null, 0, (float)num158, vector3.X, vector3.Y, num160, 0, 0);
						int num161 = -1;
						float num162 = 9999f;
						for (int num163 = 0; num163 < 255; num163 = num2 + 1)
						{
							if (Main.player[num163].active && num163 != this.whoAmI)
							{
								Vector2 vector4 = Main.player[num163].position - Main.player[this.whoAmI].position;
								if (vector4.Length() < num162)
								{
									num162 = vector4.Length();
									num161 = num163;
								}
							}
							num2 = num163;
						}
						if (num161 >= 0)
						{
							NetMessage.BroadcastChatMessage(NetworkText.FromKey("Game.HasTeleportedTo", new object[]
							{
								Main.player[this.whoAmI].name,
								Main.player[num161].name
							}), new Color(250, 250, 0), -1);
						}
					}
				}
				if (Main.netMode == 2 && num159 == 0)
				{
					NetMessage.SendData(65, -1, this.whoAmI, null, 0, (float)num158, vector3.X, vector3.Y, num160, 0, 0);
					return;
				}
				return;
			}
			case 66:
			{
				int num164 = (int)this.reader.ReadByte();
				int num165 = (int)this.reader.ReadInt16();
				if (num165 <= 0)
				{
					return;
				}
				Player player16 = Main.player[num164];
				Player player4 = player16;
				player4.statLife += num165;
				if (player16.statLife > player16.statLifeMax2)
				{
					player16.statLife = player16.statLifeMax2;
				}
				player16.HealEffect(num165, false);
				if (Main.netMode == 2)
				{
					NetMessage.SendData(66, -1, this.whoAmI, null, num164, (float)num165, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 68:
				this.reader.ReadString();
				return;
			case 69:
			{
				int num166 = (int)this.reader.ReadInt16();
				int num167 = (int)this.reader.ReadInt16();
				int num168 = (int)this.reader.ReadInt16();
				if (Main.netMode == 1)
				{
					if (num166 < 0 || num166 >= 1000)
					{
						return;
					}
					Chest chest3 = Main.chest[num166];
					if (chest3 == null)
					{
						chest3 = new Chest(false);
						chest3.x = num167;
						chest3.y = num168;
						Main.chest[num166] = chest3;
					}
					else if (chest3.x != num167 || chest3.y != num168)
					{
						return;
					}
					chest3.name = this.reader.ReadString();
					return;
				}
				else
				{
					if (num166 < -1 || num166 >= 1000)
					{
						return;
					}
					if (num166 == -1)
					{
						num166 = Chest.FindChest(num167, num168);
						if (num166 == -1)
						{
							return;
						}
					}
					Chest chest4 = Main.chest[num166];
					if (chest4.x != num167 || chest4.y != num168)
					{
						return;
					}
					NetMessage.SendData(69, this.whoAmI, -1, null, num166, (float)num167, (float)num168, 0f, 0, 0, 0);
					return;
				}
				break;
			}
			case 70:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int num169 = (int)this.reader.ReadInt16();
				int who = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					who = this.whoAmI;
				}
				if (num169 < 200 && num169 >= 0)
				{
					NPC.CatchNPC(num169, who);
					return;
				}
				return;
			}
			case 71:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int x3 = this.reader.ReadInt32();
				int y3 = this.reader.ReadInt32();
				int type8 = (int)this.reader.ReadInt16();
				byte style = this.reader.ReadByte();
				NPC.ReleaseNPC(x3, y3, type8, (int)style, this.whoAmI);
				return;
			}
			case 72:
				if (Main.netMode != 1)
				{
					return;
				}
				for (int num170 = 0; num170 < 40; num170 = num2 + 1)
				{
					Main.travelShop[num170] = (int)this.reader.ReadInt16();
					num2 = num170;
				}
				return;
			case 73:
				Main.player[this.whoAmI].TeleportationPotion();
				return;
			case 74:
				if (Main.netMode != 1)
				{
					return;
				}
				Main.anglerQuest = (int)this.reader.ReadByte();
				Main.anglerQuestFinished = this.reader.ReadBoolean();
				return;
			case 75:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				string name2 = Main.player[this.whoAmI].name;
				if (!Main.anglerWhoFinishedToday.Contains(name2))
				{
					Main.anglerWhoFinishedToday.Add(name2);
					return;
				}
				return;
			}
			case 76:
			{
				int num171 = (int)this.reader.ReadByte();
				if (num171 == Main.myPlayer && !Main.ServerSideCharacter)
				{
					return;
				}
				if (Main.netMode == 2)
				{
					num171 = this.whoAmI;
				}
				Player player17 = Main.player[num171];
				player17.anglerQuestsFinished = this.reader.ReadInt32();
				if (Main.netMode == 2)
				{
					NetMessage.SendData(76, -1, this.whoAmI, null, num171, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 77:
			{
				short type9 = this.reader.ReadInt16();
				ushort tileType = this.reader.ReadUInt16();
				short x4 = this.reader.ReadInt16();
				short y4 = this.reader.ReadInt16();
				Animation.NewTemporaryAnimation((int)type9, tileType, (int)x4, (int)y4);
				return;
			}
			case 78:
				if (Main.netMode != 1)
				{
					return;
				}
				Main.ReportInvasionProgress(this.reader.ReadInt32(), this.reader.ReadInt32(), (int)this.reader.ReadSByte(), (int)this.reader.ReadSByte());
				return;
			case 79:
			{
				int x5 = (int)this.reader.ReadInt16();
				int y5 = (int)this.reader.ReadInt16();
				short type10 = this.reader.ReadInt16();
				int style2 = (int)this.reader.ReadInt16();
				int num172 = (int)this.reader.ReadByte();
				int random = (int)this.reader.ReadSByte();
				int direction;
				if (this.reader.ReadBoolean())
				{
					direction = 1;
				}
				else
				{
					direction = -1;
				}
				if (Main.netMode == 2)
				{
					RemoteClient remoteClient = Netplay.Clients[this.whoAmI];
					remoteClient.SpamAddBlock += 1f;
					if (!WorldGen.InWorld(x5, y5, 10) || !Netplay.Clients[this.whoAmI].TileSections[Netplay.GetSectionX(x5), Netplay.GetSectionY(y5)])
					{
						return;
					}
				}
				WorldGen.PlaceObject(x5, y5, (int)type10, false, style2, num172, random, direction);
				if (Main.netMode == 2)
				{
					NetMessage.SendObjectPlacment(this.whoAmI, x5, y5, (int)type10, style2, num172, random, direction);
					return;
				}
				return;
			}
			case 80:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num173 = (int)this.reader.ReadByte();
				int num174 = (int)this.reader.ReadInt16();
				if (num174 >= -3 && num174 < 1000)
				{
					Main.player[num173].chest = num174;
					Recipe.FindRecipes();
					return;
				}
				return;
			}
			case 81:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int x6 = (int)this.reader.ReadSingle();
				int y6 = (int)this.reader.ReadSingle();
				Color color3 = this.reader.ReadRGB();
				int amount = this.reader.ReadInt32();
				CombatText.NewText(new Rectangle(x6, y6, 0, 0), color3, amount, false, false);
				return;
			}
			case 82:
				NetManager.Instance.Read(this.reader, this.whoAmI);
				return;
			case 83:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num175 = (int)this.reader.ReadInt16();
				int num176 = this.reader.ReadInt32();
				if (num175 >= 0)
				{
					NPC.killCount[num175] = num176;
					return;
				}
				return;
			}
			case 84:
			{
				int num177 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num177 = this.whoAmI;
				}
				float stealth = this.reader.ReadSingle();
				Main.player[num177].stealth = stealth;
				if (Main.netMode == 2)
				{
					NetMessage.SendData(84, -1, this.whoAmI, null, num177, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 85:
			{
				int num178 = this.whoAmI;
				byte b16 = this.reader.ReadByte();
				if (Main.netMode == 2 && num178 < 255 && b16 < 58)
				{
					Chest.ServerPlaceItem(this.whoAmI, (int)b16);
					return;
				}
				return;
			}
			case 86:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num179 = this.reader.ReadInt32();
				if (this.reader.ReadBoolean())
				{
					TileEntity tileEntity = TileEntity.Read(this.reader, true);
					tileEntity.ID = num179;
					TileEntity.ByID[tileEntity.ID] = tileEntity;
					TileEntity.ByPosition[tileEntity.Position] = tileEntity;
					return;
				}
				TileEntity tileEntity2;
				if (TileEntity.ByID.TryGetValue(num179, out tileEntity2) && (tileEntity2 is TETrainingDummy || tileEntity2 is TEItemFrame || tileEntity2 is TELogicSensor || tileEntity2 is ModTileEntity))
				{
					TileEntity.ByID.Remove(num179);
					TileEntity.ByPosition.Remove(tileEntity2.Position);
					return;
				}
				return;
			}
			case 87:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int x7 = (int)this.reader.ReadInt16();
				int y7 = (int)this.reader.ReadInt16();
				int type11 = (int)this.reader.ReadByte();
				if (!WorldGen.InWorld(x7, y7, 0))
				{
					return;
				}
				if (TileEntity.ByPosition.ContainsKey(new Point16(x7, y7)))
				{
					return;
				}
				TileEntity.PlaceEntityNet(x7, y7, type11);
				return;
			}
			case 88:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num180 = (int)this.reader.ReadInt16();
				if (num180 < 0 || num180 > 400)
				{
					return;
				}
				Item item4 = Main.item[num180];
				BitsByte bitsByte9 = this.reader.ReadByte();
				if (bitsByte9[0])
				{
					item4.color.PackedValue = this.reader.ReadUInt32();
				}
				if (bitsByte9[1])
				{
					item4.damage = (int)this.reader.ReadUInt16();
				}
				if (bitsByte9[2])
				{
					item4.knockBack = this.reader.ReadSingle();
				}
				if (bitsByte9[3])
				{
					item4.useAnimation = (int)this.reader.ReadUInt16();
				}
				if (bitsByte9[4])
				{
					item4.useTime = (int)this.reader.ReadUInt16();
				}
				if (bitsByte9[5])
				{
					item4.shoot = (int)this.reader.ReadInt16();
				}
				if (bitsByte9[6])
				{
					item4.shootSpeed = this.reader.ReadSingle();
				}
				if (!bitsByte9[7])
				{
					return;
				}
				bitsByte9 = this.reader.ReadByte();
				if (bitsByte9[0])
				{
					item4.width = (int)this.reader.ReadInt16();
				}
				if (bitsByte9[1])
				{
					item4.height = (int)this.reader.ReadInt16();
				}
				if (bitsByte9[2])
				{
					item4.scale = this.reader.ReadSingle();
				}
				if (bitsByte9[3])
				{
					item4.ammo = (int)this.reader.ReadInt16();
				}
				if (bitsByte9[4])
				{
					item4.useAmmo = (int)this.reader.ReadInt16();
				}
				if (bitsByte9[5])
				{
					item4.notAmmo = this.reader.ReadBoolean();
					return;
				}
				return;
			}
			case 89:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int x8 = (int)this.reader.ReadInt16();
				int y8 = (int)this.reader.ReadInt16();
				int netid = (int)this.reader.ReadInt16();
				int prefix = (int)this.reader.ReadByte();
				int stack5 = (int)this.reader.ReadInt16();
				TEItemFrame.TryPlacing(x8, y8, netid, prefix, stack5);
				return;
			}
			case 91:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int num181 = this.reader.ReadInt32();
				int num182 = (int)this.reader.ReadByte();
				if (num182 != 255)
				{
					int meta = (int)this.reader.ReadUInt16();
					int num183 = (int)this.reader.ReadByte();
					int num184 = (int)this.reader.ReadByte();
					int metadata = 0;
					if (num184 < 0)
					{
						metadata = (int)this.reader.ReadInt16();
					}
					WorldUIAnchor worldUIAnchor = EmoteBubble.DeserializeNetAnchor(num182, meta);
					Dictionary<int, EmoteBubble> byID = EmoteBubble.byID;
					lock (byID)
					{
						if (!EmoteBubble.byID.ContainsKey(num181))
						{
							EmoteBubble.byID[num181] = new EmoteBubble(num184, worldUIAnchor, num183);
						}
						else
						{
							EmoteBubble.byID[num181].lifeTime = num183;
							EmoteBubble.byID[num181].lifeTimeStart = num183;
							EmoteBubble.byID[num181].emote = num184;
							EmoteBubble.byID[num181].anchor = worldUIAnchor;
						}
						EmoteBubble.byID[num181].ID = num181;
						EmoteBubble.byID[num181].metadata = metadata;
						return;
					}
				}
				if (EmoteBubble.byID.ContainsKey(num181))
				{
					EmoteBubble.byID.Remove(num181);
					return;
				}
				return;
			}
			case 92:
			{
				int num185 = (int)this.reader.ReadInt16();
				float num186 = this.reader.ReadSingle();
				float num187 = this.reader.ReadSingle();
				float num188 = this.reader.ReadSingle();
				if (num185 < 0 || num185 > 200)
				{
					return;
				}
				if (Main.netMode == 1)
				{
					Main.npc[num185].moneyPing(new Vector2(num187, num188));
					Main.npc[num185].extraValue = num186;
					return;
				}
				NPC npc3 = Main.npc[num185];
				npc3.extraValue += num186;
				NetMessage.SendData(92, -1, -1, null, num185, Main.npc[num185].extraValue, num187, num188, 0, 0, 0);
				return;
			}
			case 95:
			{
				ushort num189 = this.reader.ReadUInt16();
				if (Main.netMode != 2)
				{
					return;
				}
				if (num189 < 0 || num189 >= 1000)
				{
					return;
				}
				Projectile projectile2 = Main.projectile[(int)num189];
				if (projectile2.type == 602)
				{
					projectile2.Kill();
					NetMessage.SendData(29, -1, -1, null, projectile2.whoAmI, (float)projectile2.owner, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 96:
			{
				int num190 = (int)this.reader.ReadByte();
				Player player18 = Main.player[num190];
				int num191 = (int)this.reader.ReadInt16();
				Vector2 newPos = this.reader.ReadVector2();
				Vector2 velocity4 = this.reader.ReadVector2();
				int lastPortalColorIndex = num191 + ((num191 % 2 == 0) ? 1 : -1);
				player18.lastPortalColorIndex = lastPortalColorIndex;
				player18.Teleport(newPos, 4, num191);
				player18.velocity = velocity4;
				return;
			}
			case 97:
				if (Main.netMode != 1)
				{
					return;
				}
				AchievementsHelper.NotifyNPCKilledDirect(Main.player[Main.myPlayer], (int)this.reader.ReadInt16());
				return;
			case 98:
				if (Main.netMode != 1)
				{
					return;
				}
				AchievementsHelper.NotifyProgressionEvent((int)this.reader.ReadInt16());
				return;
			case 99:
			{
				int num192 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num192 = this.whoAmI;
				}
				Player player19 = Main.player[num192];
				player19.MinionRestTargetPoint = this.reader.ReadVector2();
				if (Main.netMode == 2)
				{
					NetMessage.SendData(99, -1, this.whoAmI, null, num192, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 100:
			{
				int num193 = (int)this.reader.ReadUInt16();
				NPC npc4 = Main.npc[num193];
				int num194 = (int)this.reader.ReadInt16();
				Vector2 newPos2 = this.reader.ReadVector2();
				Vector2 velocity5 = this.reader.ReadVector2();
				int lastPortalColorIndex2 = num194 + ((num194 % 2 == 0) ? 1 : -1);
				npc4.lastPortalColorIndex = lastPortalColorIndex2;
				npc4.Teleport(newPos2, 4, num194);
				npc4.velocity = velocity5;
				return;
			}
			case 101:
				if (Main.netMode == 2)
				{
					return;
				}
				NPC.ShieldStrengthTowerSolar = (int)this.reader.ReadUInt16();
				NPC.ShieldStrengthTowerVortex = (int)this.reader.ReadUInt16();
				NPC.ShieldStrengthTowerNebula = (int)this.reader.ReadUInt16();
				NPC.ShieldStrengthTowerStardust = (int)this.reader.ReadUInt16();
				if (NPC.ShieldStrengthTowerSolar < 0)
				{
					NPC.ShieldStrengthTowerSolar = 0;
				}
				if (NPC.ShieldStrengthTowerVortex < 0)
				{
					NPC.ShieldStrengthTowerVortex = 0;
				}
				if (NPC.ShieldStrengthTowerNebula < 0)
				{
					NPC.ShieldStrengthTowerNebula = 0;
				}
				if (NPC.ShieldStrengthTowerStardust < 0)
				{
					NPC.ShieldStrengthTowerStardust = 0;
				}
				if (NPC.ShieldStrengthTowerSolar > NPC.LunarShieldPowerExpert)
				{
					NPC.ShieldStrengthTowerSolar = NPC.LunarShieldPowerExpert;
				}
				if (NPC.ShieldStrengthTowerVortex > NPC.LunarShieldPowerExpert)
				{
					NPC.ShieldStrengthTowerVortex = NPC.LunarShieldPowerExpert;
				}
				if (NPC.ShieldStrengthTowerNebula > NPC.LunarShieldPowerExpert)
				{
					NPC.ShieldStrengthTowerNebula = NPC.LunarShieldPowerExpert;
				}
				if (NPC.ShieldStrengthTowerStardust > NPC.LunarShieldPowerExpert)
				{
					NPC.ShieldStrengthTowerStardust = NPC.LunarShieldPowerExpert;
					return;
				}
				return;
			case 102:
			{
				int num195 = (int)this.reader.ReadByte();
				byte b17 = this.reader.ReadByte();
				Vector2 vector5 = this.reader.ReadVector2();
				if (Main.netMode == 2)
				{
					num195 = this.whoAmI;
					NetMessage.SendData(102, -1, -1, null, num195, (float)b17, vector5.X, vector5.Y, 0, 0, 0);
					return;
				}
				Player player20 = Main.player[num195];
				for (int num196 = 0; num196 < 255; num196 = num2 + 1)
				{
					Player player21 = Main.player[num196];
					if (player21.active && !player21.dead && (player20.team == 0 || player20.team == player21.team) && player21.Distance(vector5) < 700f)
					{
						Vector2 value = player20.Center - player21.Center;
						Vector2 vector6 = Vector2.Normalize(value);
						if (!vector6.HasNaNs())
						{
							int type12 = 90;
							float num197 = 0f;
							float num198 = 0.209439516f;
							Vector2 spinningpoint = new Vector2(0f, -8f);
							Vector2 value2 = new Vector2(-3f);
							float num199 = 0f;
							float num200 = 0.005f;
							byte b18 = b17;
							if (b18 != 173)
							{
								if (b18 != 176)
								{
									if (b18 == 179)
									{
										type12 = 86;
									}
								}
								else
								{
									type12 = 88;
								}
							}
							else
							{
								type12 = 90;
							}
							int num201 = 0;
							while ((float)num201 < value.Length() / 6f)
							{
								Vector2 position2 = player21.Center + 6f * (float)num201 * vector6 + spinningpoint.RotatedBy((double)num197, default(Vector2)) + value2;
								num197 += num198;
								int num202 = Dust.NewDust(position2, 6, 6, type12, 0f, 0f, 100, default(Color), 1.5f);
								Main.dust[num202].noGravity = true;
								Main.dust[num202].velocity = Vector2.Zero;
								num199 = (Main.dust[num202].fadeIn = num199 + num200);
								Dust dust = Main.dust[num202];
								dust.velocity += vector6 * 1.5f;
								num2 = num201;
								num201 = num2 + 1;
							}
						}
						player21.NebulaLevelup((int)b17);
					}
					num2 = num196;
				}
				return;
			}
			case 103:
				if (Main.netMode == 1)
				{
					NPC.MoonLordCountdown = this.reader.ReadInt32();
					return;
				}
				return;
			case 104:
			{
				if (Main.netMode != 1 || Main.npcShop <= 0)
				{
					return;
				}
				Item[] item5 = Main.instance.shop[Main.npcShop].item;
				int num203 = (int)this.reader.ReadByte();
				int type13 = (int)this.reader.ReadInt16();
				int stack6 = (int)this.reader.ReadInt16();
				int pre3 = (int)this.reader.ReadByte();
				int value3 = this.reader.ReadInt32();
				BitsByte bitsByte10 = this.reader.ReadByte();
				if (num203 < item5.Length)
				{
					item5[num203] = new Item();
					item5[num203].netDefaults(type13);
					item5[num203].stack = stack6;
					item5[num203].Prefix(pre3);
					item5[num203].value = value3;
					item5[num203].buyOnce = bitsByte10[0];
					return;
				}
				return;
			}
			case 105:
			{
				if (Main.netMode == 1)
				{
					return;
				}
				int i3 = (int)this.reader.ReadInt16();
				int j3 = (int)this.reader.ReadInt16();
				bool on = this.reader.ReadBoolean();
				WorldGen.ToggleGemLock(i3, j3, on);
				return;
			}
			case 106:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				HalfVector2 halfVector = default(HalfVector2);
				halfVector.PackedValue = this.reader.ReadUInt32();
				Utils.PoofOfSmoke(halfVector.ToVector2());
				return;
			}
			case 107:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				Color c = this.reader.ReadRGB();
				string text3 = NetworkText.Deserialize(this.reader).ToString();
				int widthLimit = (int)this.reader.ReadInt16();
				Main.NewTextMultiline(text3, false, c, widthLimit);
				return;
			}
			case 108:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int damage2 = (int)this.reader.ReadInt16();
				float knockBack2 = this.reader.ReadSingle();
				int x9 = (int)this.reader.ReadInt16();
				int y9 = (int)this.reader.ReadInt16();
				int angle = (int)this.reader.ReadInt16();
				int ammo = (int)this.reader.ReadInt16();
				int num204 = (int)this.reader.ReadByte();
				if (num204 != Main.myPlayer)
				{
					return;
				}
				WorldGen.ShootFromCannon(x9, y9, angle, ammo, damage2, knockBack2, num204);
				return;
			}
			case 109:
			{
				if (Main.netMode != 2)
				{
					return;
				}
				int x10 = (int)this.reader.ReadInt16();
				int y10 = (int)this.reader.ReadInt16();
				int x11 = (int)this.reader.ReadInt16();
				int y11 = (int)this.reader.ReadInt16();
				WiresUI.Settings.MultiToolMode toolMode = (WiresUI.Settings.MultiToolMode)this.reader.ReadByte();
				int num205 = this.whoAmI;
				WiresUI.Settings.MultiToolMode toolMode2 = WiresUI.Settings.ToolMode;
				WiresUI.Settings.ToolMode = toolMode;
				Wiring.MassWireOperation(new Point(x10, y10), new Point(x11, y11), Main.player[num205]);
				WiresUI.Settings.ToolMode = toolMode2;
				return;
			}
			case 110:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int type14 = (int)this.reader.ReadInt16();
				int num206 = (int)this.reader.ReadInt16();
				int num207 = (int)this.reader.ReadByte();
				if (num207 != Main.myPlayer)
				{
					return;
				}
				Player player22 = Main.player[num207];
				for (int num208 = 0; num208 < num206; num208 = num2 + 1)
				{
					player22.ConsumeItem(type14, false);
					num2 = num208;
				}
				player22.wireOperationsCooldown = 0;
				return;
			}
			case 111:
				if (Main.netMode != 2)
				{
					return;
				}
				BirthdayParty.ToggleManualParty();
				return;
			case 112:
			{
				int num209 = (int)this.reader.ReadByte();
				int num210 = (int)this.reader.ReadInt16();
				int num211 = (int)this.reader.ReadInt16();
				int num212 = (int)this.reader.ReadByte();
				int num213 = (int)this.reader.ReadInt16();
				if (num209 != 1)
				{
					return;
				}
				if (Main.netMode == 1)
				{
					WorldGen.TreeGrowFX(num210, num211, num212, num213);
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData((int)b, -1, -1, null, num209, (float)num210, (float)num211, (float)num212, num213, 0, 0);
					return;
				}
				return;
			}
			case 113:
			{
				int x12 = (int)this.reader.ReadInt16();
				int y12 = (int)this.reader.ReadInt16();
				if (Main.netMode == 2 && !Main.snowMoon && !Main.pumpkinMoon)
				{
					if (DD2Event.WouldFailSpawningHere(x12, y12))
					{
						DD2Event.FailureMessage(this.whoAmI);
					}
					DD2Event.SummonCrystal(x12, y12);
					return;
				}
				return;
			}
			case 114:
				if (Main.netMode != 1)
				{
					return;
				}
				DD2Event.WipeEntities();
				return;
			case 115:
			{
				int num214 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num214 = this.whoAmI;
				}
				Player player23 = Main.player[num214];
				player23.MinionAttackTargetNPC = (int)this.reader.ReadInt16();
				if (Main.netMode == 2)
				{
					NetMessage.SendData(115, -1, this.whoAmI, null, num214, 0f, 0f, 0f, 0, 0, 0);
					return;
				}
				return;
			}
			case 116:
				if (Main.netMode != 1)
				{
					return;
				}
				DD2Event.TimeLeftBetweenWaves = this.reader.ReadInt32();
				return;
			case 117:
			{
				int num215 = (int)this.reader.ReadByte();
				if (Main.netMode == 2 && this.whoAmI != num215 && (!Main.player[num215].hostile || !Main.player[this.whoAmI].hostile))
				{
					return;
				}
				PlayerDeathReason playerDeathReason = PlayerDeathReason.FromReader(this.reader);
				int damage3 = (int)this.reader.ReadInt16();
				int num216 = (int)(this.reader.ReadByte() - 1);
				BitsByte bitsByte11 = this.reader.ReadByte();
				bool flag14 = bitsByte11[0];
				bool pvp = bitsByte11[1];
				int num217 = (int)this.reader.ReadSByte();
				Main.player[num215].Hurt(playerDeathReason, damage3, num216, pvp, true, flag14, num217);
				if (Main.netMode == 2)
				{
					NetMessage.SendPlayerHurt(num215, playerDeathReason, damage3, num216, flag14, pvp, num217, -1, this.whoAmI);
					return;
				}
				return;
			}
			case 118:
			{
				int num218 = (int)this.reader.ReadByte();
				if (Main.netMode == 2)
				{
					num218 = this.whoAmI;
				}
				PlayerDeathReason playerDeathReason2 = PlayerDeathReason.FromReader(this.reader);
				int num219 = (int)this.reader.ReadInt16();
				int num220 = (int)(this.reader.ReadByte() - 1);
				bool pvp2 = this.reader.ReadByte()[0];
				Main.player[num218].KillMe(playerDeathReason2, (double)num219, num220, pvp2);
				if (Main.netMode == 2)
				{
					NetMessage.SendPlayerDeath(num218, playerDeathReason2, num219, num220, pvp2, -1, this.whoAmI);
					return;
				}
				return;
			}
			case 119:
			{
				if (Main.netMode != 1)
				{
					return;
				}
				int x13 = (int)this.reader.ReadSingle();
				int y13 = (int)this.reader.ReadSingle();
				Color color4 = this.reader.ReadRGB();
				NetworkText networkText = NetworkText.Deserialize(this.reader);
				CombatText.NewText(new Rectangle(x13, y13, 0, 0), color4, networkText.ToString(), false, false);
				return;
			}
			default:
				switch (b)
				{
				case 250:
					ModNet.HandleModPacket(this.reader, this.whoAmI);
					return;
				case 251:
					if (Main.netMode == 1)
					{
						ModNet.SyncClientMods(this.reader);
						return;
					}
					ModNet.SendNetIDs(this.whoAmI);
					NetMessage.SendData(3, this.whoAmI, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
					return;
				case 252:
					if (Main.netMode == 1)
					{
						ModNet.ReceiveMod(this.reader);
						return;
					}
					ModNet.SendMod(this.reader.ReadString(), this.whoAmI);
					return;
				default:
					return;
				}
				break;
			}
			if (Main.netMode != 1)
			{
				return;
			}
			Main.time = (double)this.reader.ReadInt32();
			BitsByte bitsByte12 = this.reader.ReadByte();
			Main.dayTime = bitsByte12[0];
			Main.bloodMoon = bitsByte12[1];
			Main.eclipse = bitsByte12[2];
			Main.moonPhase = (int)this.reader.ReadByte();
			Main.maxTilesX = (int)this.reader.ReadInt16();
			Main.maxTilesY = (int)this.reader.ReadInt16();
			Main.spawnTileX = (int)this.reader.ReadInt16();
			Main.spawnTileY = (int)this.reader.ReadInt16();
			Main.worldSurface = (double)this.reader.ReadInt16();
			Main.rockLayer = (double)this.reader.ReadInt16();
			Main.worldID = this.reader.ReadInt32();
			Main.worldName = this.reader.ReadString();
			Main.ActiveWorldFileData.UniqueId = new Guid(this.reader.ReadBytes(16));
			Main.ActiveWorldFileData.WorldGeneratorVersion = this.reader.ReadUInt64();
			Main.moonType = (int)this.reader.ReadByte();
			WorldGen.setBG(0, (int)this.reader.ReadByte());
			WorldGen.setBG(1, (int)this.reader.ReadByte());
			WorldGen.setBG(2, (int)this.reader.ReadByte());
			WorldGen.setBG(3, (int)this.reader.ReadByte());
			WorldGen.setBG(4, (int)this.reader.ReadByte());
			WorldGen.setBG(5, (int)this.reader.ReadByte());
			WorldGen.setBG(6, (int)this.reader.ReadByte());
			WorldGen.setBG(7, (int)this.reader.ReadByte());
			Main.iceBackStyle = (int)this.reader.ReadByte();
			Main.jungleBackStyle = (int)this.reader.ReadByte();
			Main.hellBackStyle = (int)this.reader.ReadByte();
			Main.windSpeedSet = this.reader.ReadSingle();
			Main.numClouds = (int)this.reader.ReadByte();
			for (int num221 = 0; num221 < 3; num221 = num2 + 1)
			{
				Main.treeX[num221] = this.reader.ReadInt32();
				num2 = num221;
			}
			for (int num222 = 0; num222 < 4; num222 = num2 + 1)
			{
				Main.treeStyle[num222] = (int)this.reader.ReadByte();
				num2 = num222;
			}
			for (int num223 = 0; num223 < 3; num223 = num2 + 1)
			{
				Main.caveBackX[num223] = this.reader.ReadInt32();
				num2 = num223;
			}
			for (int num224 = 0; num224 < 4; num224 = num2 + 1)
			{
				Main.caveBackStyle[num224] = (int)this.reader.ReadByte();
				num2 = num224;
			}
			Main.maxRaining = this.reader.ReadSingle();
			Main.raining = (Main.maxRaining > 0f);
			BitsByte bitsByte13 = this.reader.ReadByte();
			WorldGen.shadowOrbSmashed = bitsByte13[0];
			NPC.downedBoss1 = bitsByte13[1];
			NPC.downedBoss2 = bitsByte13[2];
			NPC.downedBoss3 = bitsByte13[3];
			Main.hardMode = bitsByte13[4];
			NPC.downedClown = bitsByte13[5];
			Main.ServerSideCharacter = bitsByte13[6];
			NPC.downedPlantBoss = bitsByte13[7];
			BitsByte bitsByte14 = this.reader.ReadByte();
			NPC.downedMechBoss1 = bitsByte14[0];
			NPC.downedMechBoss2 = bitsByte14[1];
			NPC.downedMechBoss3 = bitsByte14[2];
			NPC.downedMechBossAny = bitsByte14[3];
			Main.cloudBGActive = (float)(bitsByte14[4] ? 1 : 0);
			WorldGen.crimson = bitsByte14[5];
			Main.pumpkinMoon = bitsByte14[6];
			Main.snowMoon = bitsByte14[7];
			BitsByte bitsByte15 = this.reader.ReadByte();
			Main.expertMode = bitsByte15[0];
			Main.fastForwardTime = bitsByte15[1];
			Main.UpdateSundial();
			bool flag15 = bitsByte15[2];
			NPC.downedSlimeKing = bitsByte15[3];
			NPC.downedQueenBee = bitsByte15[4];
			NPC.downedFishron = bitsByte15[5];
			NPC.downedMartians = bitsByte15[6];
			NPC.downedAncientCultist = bitsByte15[7];
			BitsByte bitsByte16 = this.reader.ReadByte();
			NPC.downedMoonlord = bitsByte16[0];
			NPC.downedHalloweenKing = bitsByte16[1];
			NPC.downedHalloweenTree = bitsByte16[2];
			NPC.downedChristmasIceQueen = bitsByte16[3];
			NPC.downedChristmasSantank = bitsByte16[4];
			NPC.downedChristmasTree = bitsByte16[5];
			NPC.downedGolemBoss = bitsByte16[6];
			BirthdayParty.ManualParty = bitsByte16[7];
			BitsByte bitsByte17 = this.reader.ReadByte();
			NPC.downedPirates = bitsByte17[0];
			NPC.downedFrost = bitsByte17[1];
			NPC.downedGoblins = bitsByte17[2];
			Sandstorm.Happening = bitsByte17[3];
			DD2Event.Ongoing = bitsByte17[4];
			DD2Event.DownedInvasionT1 = bitsByte17[5];
			DD2Event.DownedInvasionT2 = bitsByte17[6];
			DD2Event.DownedInvasionT3 = bitsByte17[7];
			if (flag15)
			{
				Main.StartSlimeRain(true);
			}
			else
			{
				Main.StopSlimeRain(true);
			}
			Main.invasionType = (int)this.reader.ReadSByte();
			if (!ModNet.AllowVanillaClients)
			{
				WorldIO.ReceiveModData(this.reader);
			}
			Main.LobbyId = this.reader.ReadUInt64();
			Sandstorm.IntendedSeverity = this.reader.ReadSingle();
			if (Netplay.Connection.State == 3)
			{
				Netplay.Connection.State = 4;
				return;
			}
			return;
			IL_4A71:
			int num225 = (int)this.reader.ReadByte();
			if (Main.netMode == 2)
			{
				num225 = this.whoAmI;
			}
			else if (num225 == Main.myPlayer && !Main.ServerSideCharacter)
			{
				return;
			}
			Player player24 = Main.player[num225];
			for (int num226 = 0; num226 < 22; num226 = num2 + 1)
			{
				player24.buffType[num226] = (int)(ModNet.AllowVanillaClients ? ((ushort)this.reader.ReadByte()) : this.reader.ReadUInt16());
				if (player24.buffType[num226] > 0)
				{
					player24.buffTime[num226] = 60;
				}
				else
				{
					player24.buffTime[num226] = 0;
				}
				num2 = num226;
			}
			if (Main.netMode == 2)
			{
				NetMessage.SendData(50, -1, this.whoAmI, null, num225, 0f, 0f, 0f, 0, 0, 0);
				return;
			}
			return;
		}

		// Token: 0x0400075D RID: 1885
		public const int readBufferMax = 131070;

		// Token: 0x0400075E RID: 1886
		public const int writeBufferMax = 131070;

		// Token: 0x0400075F RID: 1887
		public bool broadcast;

		// Token: 0x04000760 RID: 1888
		public byte[] readBuffer = new byte[131070];

		// Token: 0x04000761 RID: 1889
		public byte[] writeBuffer = new byte[131070];

		// Token: 0x04000762 RID: 1890
		public bool writeLocked;

		// Token: 0x04000763 RID: 1891
		public int messageLength;

		// Token: 0x04000764 RID: 1892
		public int totalData;

		// Token: 0x04000765 RID: 1893
		public int whoAmI;

		// Token: 0x04000766 RID: 1894
		public int spamCount;

		// Token: 0x04000767 RID: 1895
		public int maxSpam;

		// Token: 0x04000768 RID: 1896
		public bool checkBytes;

		// Token: 0x04000769 RID: 1897
		public MemoryStream readerStream;

		// Token: 0x0400076A RID: 1898
		public MemoryStream writerStream;

		// Token: 0x0400076B RID: 1899
		public BinaryReader reader;

		// Token: 0x0400076C RID: 1900
		public BinaryWriter writer;
	}
}
